Python
Displaying 1-5 of 5 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
-zaril-

Oh my gawd how easy some things will be, just look at this Python example of a telephone list:

tel = {'jack': 4098, 'sape': 4139}
tel['guido'] = 4127
tel
{'sape': 4139, 'guido': 4127, 'jack': 4098}
tel['jack']
4098
del tel['sape']
tel['irv'] = 4127
tel
{'guido': 4127, 'irv': 4127, 'jack': 4098}
tel.keys()
['guido', 'irv', 'jack']
tel.has_key('guido')
1

Now... how do you add an item? Should be SIMPLE! Remember that # is the new one-liner comment.

itemlist['PheonixDown'] = 1
itemlist['Potion'] = 3
itemlist
{'PheonixDown': 1, 'Potion': 3}
itemlist['Potion']
3

For those who haven't read Python yet, the might seem confusing. However, lists are very useful for items (imho) there might be a better way, but for Confluence I've pre-coded something I don't know if it works, but here is how to add an item in the code:

def additem(itemname, itemqty=1)
itemlist['itemname'] = itemqty

I add 4 potions by typing:

additem('Potion',4)

I'm making a delete function as well, that will be as easy as this (taking away 2 potions):

delitem('Potion',2)


I am no genius in Python, I'm just starting, but this is just one aspect of the item list on how Python is golden for it. Any corrections? Errata? Flaming? Be my guest, just reply. I want to know if I have coded this incorrectly.



. / ~ - www.lightcharm.com - ~ \ . "fate is like a double-edged sword"

Posted on 2001-06-01 12:33:43

-zaril-

Sorry, it seems like this messageboard deletes the "arrow-brackets" and therefor makes the code quite oogly. I'm hoping someone understand anyway. The whole point is, lists seem to save a lot of time and coding space for item systems AND more. Anything from menus to battles I believe. Toodles!



. / ~ - www.lightcharm.com - ~ \ . "fate is like a double-edged sword"

Posted on 2001-06-01 12:40:35

andy

It's a bit of a pain *cough*SoulBain*cough*, ^_^ but you can use &nbsp where you want to indent.

def blah(x):
   DoSomething()



'Never confuse a single defeat with a final defeat.' -F. Scott Fitzgerald

Posted on 2001-06-01 18:13:44

andy

Much to my surprise, my testbox now has a system.pyc file in it! (I didn't run any compiler explicitly)

So, not only does Python compile at runtime, but it saves the compiled file!! Is that cool or what? ^_^



'Never confuse a single defeat with a final defeat.' -F. Scott Fitzgerald

Posted on 2001-06-01 18:16:26

andy

def additem(itemname, itemqty=1)
   itemlist['itemname'] = itemqty

Should be:

def additem(itemname, itemqty=1)
   itemlist[itemname] = itemqty

But I would do this instead:

def additem(itemname, itemqty=1)
   if itemlist.has_key[itemname]:
      itemlist[itemname]+=itemqty
   else
      itemlist['itemname'] = itemqty

itemlist.has_key[itemname] will return true if there's already itemname's in your inventory, so you just increment the value instead. If not, then you create a new key by assigning it flat out. :)



'Never confuse a single defeat with a final defeat.' -F. Scott Fitzgerald

Posted on 2001-06-01 18:42:17


Displaying 1-5 of 5 total.
1
 
Newest messages

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.