Welcome to the Builder Academy

Question room.people and Curly Braces

More
26 Jul 2015 21:45 #5463 by krell
Replied by krell on topic room.people and Curly Braces

thomas wrote: "set next_char room.people.vnum" does not do what you expect. This means, literally, "give me the vnum of the first char in the room", as a text string (1234). This is, generally - as I stated earlier - not what you want to store.

Instead, you will want to use this formula:

Code:
* it doesn't matter what the variable is called. We use iterator here to make it obvious. set people_iterator %room.people% * check that there is actually a person in the variable at this point while %people_iterator% * since we are not purging the current person (or killing them in the loop), just work with the var * otherwise, store a "next_in_room" variable here. * increase our counter (why are you adding the people to a list? this seems overly complicated) eval num %num% + 1 * now STUFF all of the people into a list, 1 to n! * this stores a fully-fledged character variable at victim[X]. * This is useful for dg commands like %force%, %kill%, etc. set victim[%num%] %people_iterator% * if you just want their ID (not that I see that as useful), use this: set victim[%num%] %people_iterator.id% * if the vnum is what you want to store, you could do it like this: set victim[%num%] %people_iterator.vnum% * now, we move our iterator to the next character in the room set people_iterator %people_iterator.next_in_room% * and complete the loop end


Ah, much clearer. Thanks.

But, will you PLEASE enlighten me about what you need the victim-array for? The only reason I can see would be to store the list for later use. And that seems, as I mention in the code above, somewhat convoluted and complicating. I mean, you'll have too loop over the array afterwards to make any use of it. I'd have gone with the more tried and tested solution here:

Code:
* obtain first char in room - adjust to %actor.room.people%, %self.room.people%, etc. set person %room.people% * as before, check if the loop is done while %person% * because this loop is generic, we might destroy the character and thus move it out of the room. Save the next-value. set next %person.next_in_room% * do bad, bad stuff to the person if they are not fidos if %person.vnum% != 3001 %echo% %person.name% is KILLED! %kill% %person% end * now, go to next person. Use the stored value from above. Perhaps the person no longer exist at this point. set person %next% * and loop end


That particular list is actually used in one of my scripts to pick a player at random.
Code:
* Randomly pick a PC to tormenent eval num %%random.%num%%% eval do_vict %%victim[%num%]%% if (some condition) (do something annoying/unpleasant to victim) end

Perhaps I'm not as clever as I thought I was.

Please Log in or Create an account to join the conversation.

More
27 Jul 2015 19:17 #5464 by thomas
Replied by thomas on topic room.people and Curly Braces
actually that is just about the one reason you'd need such a list :) brilliant.

Please Log in or Create an account to join the conversation.

Time to create page: 0.192 seconds