FAQ Search Memberlist Usergroups
Jolt Country Forum Index
Register Profile Log in to check your private messages Log in
Log in Log in

for i in player

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Jolt Country Forum Index -> Hugo's House of Horrors
View previous topic :: View next topic  
Author Message
Ice Cream Jonsey



Joined: 27 Apr 2002
Posts: 20088
Location: Colorado

PostPosted: Mon May 12, 2008 12:50 am    Post subject: for i in player Reply with quote

OK, I am absolutely losing my mind. I can't understand what is going on here.

I am doing the following to get rid of everything in the player's inventory:

Code:
      
for i in player
{
   print i.name
   remove i
}


And this code only prints the name of the first object in the player, and only removes that object. The other two he happens to have are left there, so I assume the for loop closes.

If I do not have the "remove i" line in there, it prints all three objects.

... but here's the thing. I've used this same code in at least two other games. I *know* it works. It iterates through the player and removes everything the player has.

... doesn't it? I guess there is a slight chance that the game never did it for Necrotic Drift, and I never noticed, but I could have sworn that I'd see a tester try to do something weird if that was the case.

I am really, really confused. I assume that you just can't "remove i" then? Because that kills the loop? What do you guys do when you want to remove the player character of all items he might have?
_________________
the dark and gritty...Ice Cream Jonsey!
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Ice Cream Jonsey



Joined: 27 Apr 2002
Posts: 20088
Location: Colorado

PostPosted: Mon May 12, 2008 12:58 am    Post subject: Reply with quote

Nevermind. While that code WAS in Necrotic Drift, I had the following above it. I guess I did both, but the following was the thing that actually worked:

Code:
routine EmptyTarget(obj)
{
local i, j, c

   for i in obj
   {
      c++
   }

   if c ~= 0
   {
      while c > 0
      {
          for i in obj
          {
             j = i

          }

          remove j
          c--
      }
   }
}

_________________
the dark and gritty...Ice Cream Jonsey!
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Tdarcos



Joined: 16 May 2008
Posts: 4441
Location: University Park, Maryland

PostPosted: Fri May 16, 2008 10:09 am    Post subject: Re: for i in player Reply with quote

Ice Cream Jonsey wrote:
OK, I am absolutely losing my mind. I can't understand what is going on here.

I am doing the following to get rid of everything in the player's inventory:

Code:
      
for i in player
{
   print i.name
   remove i
}



I have a thought. The "remove" is deleting items from the top down and the new items are being sucked up from the bottom to collapse the array. Thus the items are disappearing as a result. Consider this

A
B
C
D

On the first pass, it shows A and deletes it, but now B is number 1 (because number 1 is deleted) so now it shows C, deletes that one, and then D is number 2 and the list has been exhausted.

--
Paul Robinson - paul@paul-robinson.us - My Blog
_________________
The lessons of history teach us - if they teach us anything - that no one learns the lessons of history.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Ice Cream Jonsey



Joined: 27 Apr 2002
Posts: 20088
Location: Colorado

PostPosted: Fri May 16, 2008 10:14 am    Post subject: Reply with quote

Paul!!!!! Ben has spoke very glowingly of you, so please let me welcome you to the BBS. It is great to have you here. And yeah, I do believe that's exactly what I was doing with that little loop right there. I should have a feature to my text editor that lets me hover over code and see what time I wrote it. If it's beyond two in the morning, a little pop-up window should come up and say, "WARNING: PROBABLE SLOP!"

Once again, thanks for stopping by, and I hope you have some fun on this BBS.

-- Robb
_________________
the dark and gritty...Ice Cream Jonsey!
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Tdarcos



Joined: 16 May 2008
Posts: 4441
Location: University Park, Maryland

PostPosted: Tue Jul 01, 2008 8:42 am    Post subject: Reply with quote

Ice Cream Jonsey wrote:
And yeah, I do believe that's exactly what I was doing with that little loop right there.


I think I've probably been bitten by that at one time or another; typical practice is either do delete from the bottom up, or start at the top, process the items then delete the entire list once one passes the last one. Either way will work, but deleting from the top down almost certainly won't.
_________________
The lessons of history teach us - if they teach us anything - that no one learns the lessons of history.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Roody_Yogurt



Joined: 29 Apr 2002
Posts: 1993
Location: Milwaukee

PostPosted: Fri Dec 03, 2010 3:42 pm    Post subject: Reply with quote

I'm sure the Necrotic Drift code is more useful, but here's my own take on the initial problem:

Code:
 while child(player) ~= 0
   {
   for i in player
      {
      print i.name
      remove i
      }
   }


I can only imagine that in the first code, at the end of the for loop, the code thinks, welp, just got rid of i- guess I'm done! Definitely a bit counter-intuitive so I guess it's yet another thing somebody ought to keep in mind.
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Jolt Country Forum Index -> Hugo's House of Horrors All times are GMT - 7 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001 phpBB Group

Theme by Kage Musha - RPG Garden

Copyrights and trademarks are all of the belonging company. No copyright Infringement intended