Page 1 of 1
what is the opposite of "append"?
Posted: Thu Mar 24, 2011 9:34 pm
by bozance
Hello,
Does anyone know what the opposite of "append" is?
In my inventory here is how I add a gun with bullets:
$mp.inv.append("gun (%d/6)" % ammo)
Not sure how to remove it. Please help!
Re: what is the opposite of "append"?
Posted: Thu Mar 24, 2011 10:28 pm
by Megaman Z
based off of
official documentation, the exact opposite of append is pop(
) (which, given no parameters, removes the last entry from the array, but if given a parameter, removes the specified item in the array. remember arrays count from 0 upwards - "1" is the SECOND item in an array)
Do note that you're going to have to keep track of what item is where in the array, and that's going to take a bit of trial and error in some cases.
Re: what is the opposite of "append"?
Posted: Thu Mar 24, 2011 10:45 pm
by Aleema
Re: what is the opposite of "append"?
Posted: Thu Mar 24, 2011 10:49 pm
by bozance
Thanks! I am a bit clueless with this stuff, so I'm not sure how to approach this.
Can you provide an example of how I might implement this? Doesn't have to work, exactly... I just want to know what it generally would look like.
$mp.inv.pop("gun (%d/6)" % ammo)?
I read the documentation but I suck at comprehending it.
Re: what is the opposite of "append"?
Posted: Thu Mar 24, 2011 10:53 pm
by bozance
Actually based on your response I tried $mp.inv.pop(0), which worked!
Re: what is the opposite of "append"?
Posted: Thu Mar 24, 2011 10:57 pm
by Aleema
Aw, c'mon. My answer was totally right. Give me some points.

Re: what is the opposite of "append"?
Posted: Thu Mar 24, 2011 11:01 pm
by bozance
Does remove really work? I couldn't get that going.
Re: what is the opposite of "append"?
Posted: Thu Mar 24, 2011 11:02 pm
by Megaman Z
bozance wrote:Thanks! I am a bit clueless with this stuff, so I'm not sure how to approach this.
Can you provide an example of how I might implement this? Doesn't have to work, exactly... I just want to know what it generally would look like.
$mp.inv.pop("gun (%d/6)" % ammo)?
I read the documentation but I suck at comprehending it.
yeah, it takes a bit of work to figure some things out.
bozance wrote:Actually based on your response I tried $mp.inv.pop(0), which worked!
...be careful on that one - pop(0) removes the first item in the array, regardless of what it is.
remove(x) removes the first occurrence of x in the array. if you have an array [5, 3, "beer", 5, 2, "beer", "women"] and use remove("beer") and remove(5), the resulting array (after both are done) will be [3, 5, 2, "beer", "women"]
Aleema wrote:Aw, c'mon. My answer was totally right. Give me some points.

Yeah, I missed remove when I was glancing through the page. my bad on that one.
Re: what is the opposite of "append"?
Posted: Thu Mar 24, 2011 11:04 pm
by Aleema
It totally works, I use it myself. It might be fickle with your variable in there, though. Pop() is going to rely on the placement of your item in the list, and if you don't know the place, then Remove() works because it simply finds it for you.
Re: what is the opposite of "append"?
Posted: Thu Mar 24, 2011 11:14 pm
by bozance
Excellent. I'm going to put the gun and ammo counter in a separate frame, apart from inventory. Remove works fine with just regular strings, so I'll stick with those for inventory items.
Thanks for all your help.