room.people and Curly Braces

  • Krell
  • Krell's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
6 years 3 months ago #5435 by Krell
room.people and Curly Braces was created by Krell
When I use the people argument to room I get this closing curly brace in front of the result. It makes it difficult where a script requires some math between different MOBs, rooms or objects IDs.

eg:
%echo% %self.room.people%

Will echo }1 if I'm in the same room as the MOB it's attached too.

So, am I only seeing this on my copy of the MUD or is this an intentional design?

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

More
6 years 3 months ago #5436 by Parnassus
Replied by Parnassus on topic room.people and Curly Braces
I don't understand the bit about doing math between ids. If you're trying to subtract the id of mob1 from the id of mob2, it seems to me you might as well almost use random numbers.

As far as I know, the curly brackets DO indicate ids but I can't think of a time I've ever used them although they do make things more specific. For instance, I want to indicate this fido instead of that fido but they both have the same vnum. However, I can't think of a use to take this fido's id and subtract it from that fido's id.

I think the }1 is you, the first file. The }ids on players seem set but on other things seem changeable. I know that mobs will change, depending on when they're loaded, but I don't know if a sentinel mob that's limited to one instance will always be the same since it will always load at the same place on the list. I also don't know if rooms change after reboot.

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

  • Krell
  • Krell's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
6 years 3 months ago #5437 by Krell
Replied by Krell on topic room.people and Curly Braces

I don't understand the bit about doing math between ids. If you're trying to subtract the id of mob1 from the id of mob2, it seems to me you might as well almost use random numbers.


If you have two different MOBs that load in a zone they will have id's that change on loading, but the values between them will always n apart. That's why I'd want to do math. :)

As far as I know, the curly brackets DO indicate ids but I can't think of a time I've ever used them although they do make things more specific. For instance, I want to indicate this fido instead of that fido but they both have the same vnum. However, I can't think of a use to take this fido's id and subtract it from that fido's id.


I'm trying to find a way to use differences in VNUMs. I can't seem to figure out the proper inheritance for that to work though with the script I'm working on.

I think the }1 is you, the first file.


Yes, that is correct. ;)

The }ids on players seem set but on other things seem changeable. I know that mobs will change, depending on when they're loaded, but I don't know if a sentinel mob that's limited to one instance will always be the same since it will always load at the same place on the list. I also don't know if rooms change after reboot.


Please see first response above.

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

More
6 years 3 months ago #5438 by Parnassus
Replied by Parnassus on topic room.people and Curly Braces
Have you tried using the id as a string and stripping the first character, then using the remainder as a number? I remember seeing how to strip the character but I've forgotten it right now.

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

  • Krell
  • Krell's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
6 years 3 months ago #5439 by Krell
Replied by Krell on topic room.people and Curly Braces
I was considering doing that, but I don't know how with dg. I'd probably have to convert the string to integer too.

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

More
6 years 3 months ago #5440 by Parnassus
Replied by Parnassus on topic room.people and Curly Braces
Hmm, words use extract, but I still can't remember characters :(

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

More
6 years 3 months ago #5441 by Parnassus
Replied by Parnassus on topic room.people and Curly Braces
It might be something to do with charat:
charat     - set new variable %text/var.charat(index)% i.e. set phrase testing, 
             set var1 %phrase.charat(2)% now %var1% == e

I wonder if you could subtract %phrase.charat(1)% from %phrase% somehow?

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

  • Krell
  • Krell's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
6 years 3 months ago #5442 by Krell
Replied by Krell on topic room.people and Curly Braces
Or possibly contains(). Hrm, this will require more thought and research. Thanks.

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

More
6 years 3 months ago #5443 by Parnassus
Replied by Parnassus on topic room.people and Curly Braces
How crazy is this? You take the strlen, and charat for strnlen, strlen-1 and strlen-2. Then you put them all together backwards for the two ids and subtract one from the other.

I figure there has to be an easier way but I'm something of a trigger cobbler.

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

  • Krell
  • Krell's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
6 years 3 months ago - 6 years 3 months ago #5444 by Krell
Replied by Krell on topic room.people and Curly Braces
I actually hit on a similar solution for stripping the lead character, except I hadn't figured our how to put the string back together before I hit the hay. I spent much of the morning working on it until I realized I was trying to hard. This what I came up with that would allow me to math on MUD ID's, with proper refining of course. It's probably still a bit over complicated. :-)

if 1 < 2
  %echo% Krell's ID is %self.room.people%
  *set actor_id %self.room.people%
  set actor_id }1343
  %echo% actor_id is %actor_id%
  set slen %actor_id.strlen%
  %echo% slen is %slen%!
  set num 1 
  set nnum 2
  set actor_iid 
  while %num% <= %slen%
     %echo% actor_id at %num% is %actor_id.charat(%num%)
     %echo% actor_id at %nnum% is %actor_id.charat(%nnum%)
     eval actor_iid %actor_iid%%actor_id.charat(%nnum%)%
     eval nnum %nnum% + 1
     eval num %num% + 1
  done
  %echo% actor_iid at 1st element is %actor_iid.charat(1)%
  %echo% actor_iid is %actor_iid%
  set slen %actor_iid.strlen%
  %echo% length of actor_iid is %slen%
end

Addendum

More generally then:
set slen %<variable>.strlen%
set num 2 
while %num% <= %slen%
   eval <variable2> %<variable2>%%<variable>.charat(%num%)%
   eval num %num% + 1
done
Last edit: 6 years 3 months ago by Krell. Reason: First chance to add generalized code for script since travelling

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

More
6 years 2 months ago #5451 by thomas
Replied by thomas on topic room.people and Curly Braces
%room.people% is a metavariable. It holds a "characterinfo" variable for the first char in the room.
When echo'ed, it shows the internal ID of the character, prepended by a character unlikely to be the first in a string ('}'). It is not part of the dg API and can be changed without any notice.

As for creating character pointers by doing "set actor_id }1234", you are running into all kinds of potential problems in the long run.

If you need the the id, just extract it directly with %room.people.id%. Using it for calculations seems rather strange to me, as this is an internal id, which may change to another representation in the future (a hash comes to mind, for instance).

As a side note - using %room.people% for anything other than getting the first character for looping, seems suspicious to me.

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

  • Krell
  • Krell's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
6 years 2 months ago #5453 by Krell
Replied by Krell on topic room.people and Curly Braces

%room.people% is a metavariable. It holds a "characterinfo" variable for the first char in the room.
When echo'ed, it shows the internal ID of the character, prepended by a character unlikely to be the first in a string ('}'). It is not part of the dg API and can be changed without any notice.


But I'm trying to remove the first non numeric character in the string. I don't want it.

As for creating character pointers by doing "set actor_id }1234", you are running into all kinds of potential problems in the long run.


Again, I don't want to use that first non numeric character. I was trying to figure out a general way of removing it so I don't have to depend on using }# if comparing IDs. Secondly, I only used }# in my test script for testing purposes, to see if the } was removed.

If you need the the id, just extract it directly with %room.people.id%. Using it for calculations seems rather strange to me, as this is an internal id, which may change to another representation in the future (a hash comes to mind, for instance).


See above. For reasons you state just above and prior are reasons why I'm trying to strip out the non numeric.

As a side note - using %room.people% for anything other than getting the first character for looping, seems suspicious to me.


Perhaps it is, in your post to Parnassus's thread you seem to indicate that the character's VNUM can be directly derived from the ID. If that's true then I can readily modify the scripts I'm working on to take advantage of that.

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

More
6 years 2 months ago #5454 by thomas
Replied by thomas on topic room.people and Curly Braces
oh, I am obviously struggling with getting my point across. %actor.id% (and by extension, %actor.room.people.id% when the actor is the only person, or the latest arrival in the room) returns the internal id without the preceding }.

that is, %}1234.id% == 1234. (I am certain this won't work literally, but means that "you get the ID without special chars when you ask for the id subfield of a variable").

You can also, since the people-var is a general character-type variable, get the vnum by using %room.people.vnum%. But, you should be looping as in that other question - the latest arrival (typically the player) will be the first in line, and players have an empty vnum field.

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

  • Krell
  • Krell's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
6 years 2 months ago #5455 by Krell
Replied by Krell on topic room.people and Curly Braces
Thanks Thomas, I think I understand now.

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

  • Krell
  • Krell's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
6 years 2 months ago - 6 years 2 months ago #5458 by Krell
Replied by Krell on topic room.people and Curly Braces
Okay, I'm checking my understanding here. If I have a script with the following code

set next_char room.people.vnum
.
.
while %next_char%
        set tmp_char %next_char.next_in_room%
        * Count the number of people in the room.
        eval num %num% + 1
        * now STUFF all of the people into a list, 1 to n!
        set victim[%num%] %next_char%
        set next_char %tmp_char%
done

next_char will always be IDs because of tmp_char.next_in_room. If I modify my code thusly though.

set next_char room.people.vnum
.
.
while %next_char%
        set tmp_char %next_char.next_in_room%
        set next_vnum tmp_char.vnum
        * Count the number of people in the room.
        eval num %num% + 1
        * now STUFF all of the people into a list, 1 to n!
        set victim[%num%] %next_char%
        set next_char %next_vnum%
done

I could fill my list with VNUMs instead of IDs? Sorry if I seem a bit thick, but I want to make sure I have a handle on this. Thanks.
Last edit: 6 years 2 months ago by Krell.

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

More
6 years 2 months ago #5459 by Parnassus
Replied by Parnassus on topic room.people and Curly Braces
For some reason I thought that you were talking about different instances of the same mob. For instance, there are a lot of fidos running around TBA. There are two different vnums but 40 instances. If you were trying to distinguish between two of the same vnum of fidos, vnum wouldn't do it but id would.

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

More
6 years 2 months ago #5461 by thomas
Replied by thomas on topic room.people and Curly Braces
"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:
* 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

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:
* 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

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

  • Krell
  • Krell's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
6 years 2 months ago #5462 by Krell
Replied by Krell on topic room.people and Curly Braces
Well Parna, I was talking about two different MOBs in the same zone. I was having trouble automatically deriving their VNUMs and thought finding the IDs would work better for what I had in mind. Seems I might have been wrong.

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

  • Krell
  • Krell's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
6 years 2 months ago #5463 by Krell
Replied by Krell on topic room.people and Curly Braces

"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:
* 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:

* 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.
* 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
6 years 2 months ago #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.177 seconds