Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
Math
Beginner


Joined: 25 Apr 2006
Posts: 10

PostPosted: Tue Apr 25, 2006 11:35 pm   

Help With A Script
 
I am attempting to create a script to automatically kill all mobs in a single room. I track the IDs of the mobs and the counts of each type with two arrays:

Code:
#VAR mob_types %array("dog","cat","bird")
#VAR mob_counts %array(0,0,0)


I have an alias that combines a lot of offensive attacks named kk. I simplified it here with just a kill command:

Code:
#ALIAS kk {kill %1}


Triggers are setting the counts correctly. I also created an alias that loops through all the counts for one greater than zero. If one is found, that particular mob is then attacked:

Code:
#ALIAS kill_next {
#VAR index 0
#VAR mobs 0
#WHILE (@index <= %arrhigh( mob_types)) {
  #ADD mobs %arrget( mob_counts, @index)
  #IF (@mobs > 0 AND @run_attacked = "No") {
    #VAR run_attacked {Yes}
    #SAY %cr %arrget( mob_types, @index)
    kk %arrget( mob_types, @index)
    #VAR index %arrhigh( mob_types)
    }
  #ADD index 1
  }
}


The problem I am encountering is that the first mob in a room gets attacked successfully. However, any mobs in the same room are not attacked. For some reason, the kk alias is not receiving the ID of the mob the next time I call kill_next.

The #SAY command above the kk alias call does display the ID of the mob I wish to kill, but the alias is not receiving the mob ID as a parameter. It works fine the first time, but it simply sends "kill" to the MUD after the initial kill.

I attempted to add the %eval() function around the %arrget, but this did not help.

Does anyone have any ideas?

Thanks.
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Wed Apr 26, 2006 9:54 am   
 
Simplify you life use a list instead. The commands and functions you will want to pay attention to for it are #ADDITEM, %pop, %numitems, and %item
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Math
Beginner


Joined: 25 Apr 2006
Posts: 10

PostPosted: Wed Apr 26, 2006 10:08 am   I Thought About That
 
The mobs are not static. They do wander. When I slow walk into a new room, triggers are detecting the number of different mob types in a zone and updating all counts accordingly. I have triggers also updating the counts for when different types of mobs leave the room or enter it. This part is working flawlessly. A list or a stack would be very difficult to change in this situation.

I just do not understand what the problem is with the alias not receiving the parameter on the second kill. I see that the correct mob to kill next is being displayed on the screen via #SAY, but somehow, it is being lost when passed to the kk alias.

Is this a bug?
Reply with quote
Math
Beginner


Joined: 25 Apr 2006
Posts: 10

PostPosted: Wed Apr 26, 2006 10:30 am   This Is Starting To Look Like An Alias Bug
 
To test this out, I removed my kk alias from the kill_next alias as below:

Code:
#ALIAS kill_next {
#VAR index 0
#VAR mobs 0
#WHILE (@index <= %arrhigh( mob_types)) {
  #ADD mobs %arrget( mob_counts, @index)
  #IF (@mobs > 0 AND @run_attacked = "No") {
    #VAR run_attacked {Yes}
    #SAY %cr %arrget( mob_types, @index)
    kill %arrget( mob_types, @index)
    #VAR index %arrhigh( mob_types)
    }
  #ADD index 1
  }
}


Now, the script works perfectly. After the first of three of the same mob type is killed, the next one gets attacked successfully. There appears to be a problem with aliases receiving certain types of parameters.

I did attempt to create a new variable to pass to the kill_next alias thinking this might work better, but it results in the same problem :/

Is anyone aware of a way I can get this to work?
Reply with quote
Vodoc
Apprentice


Joined: 11 Apr 2003
Posts: 119
Location: Sweden

PostPosted: Wed Apr 26, 2006 10:37 am   
 
Is the identifier passed on to the kk alias always one word consisting only of a-z chars? If it contains spaces, commas or other chars then must you surround the identifier with appropriate delimiters. If this is not the case then might you have encountered a mighty strange bug.
Reply with quote
Math
Beginner


Joined: 25 Apr 2006
Posts: 10

PostPosted: Wed Apr 26, 2006 10:52 am   
 
I have not found a way to resolve passing an array element to an alias correctly, but I did find a work around:

Code:
#ALIAS kill_next {
#VAR index 0
#VAR mobs 0
#WHILE (@index <= %arrhigh( mob_types)) {
  #ADD mobs %arrget( mob_counts, @index)
  #IF (@mobs > 0 AND @run_attacked = "No") {
    #VAR run_attacked {Yes}
    kill %arrget( mob_types, @index)
    kk
    #VAR index %arrhigh( mob_types)
    }
  #ADD index 1
  }
}


The kk alias works with or without a parameter, so just using the mud's kill command initiates combat just fine.
Reply with quote
Math
Beginner


Joined: 25 Apr 2006
Posts: 10

PostPosted: Wed Apr 26, 2006 10:55 am   
 
Vodoc wrote:
Is the identifier passed on to the kk alias always one word consisting only of a-z chars? If it contains spaces, commas or other chars then must you surround the identifier with appropriate delimiters. If this is not the case then might you have encountered a mighty strange bug.


The mob ID is always a single word with the characters A through Z with no spaces.
Reply with quote
Vodoc
Apprentice


Joined: 11 Apr 2003
Posts: 119
Location: Sweden

PostPosted: Wed Apr 26, 2006 11:16 am   
 
Using blank settings and issuing the following commands works without a hitch
Code:
#VAR mob_types %array("dog","cat","bird")
#ALIAS kk {kill %1}
kk %arrget( mob_types, 1 )

So passing array elements to an alias does work. Can you cut out as much as possible from your scripts until you got a working testcase that shows any buggy behaviour?

edit: I noticed for instance that you set the variable @run_attacked to "Yes" but don't provide any trigger etc in your examples that resets it to "No", can there be any glitch there?
Reply with quote
Math
Beginner


Joined: 25 Apr 2006
Posts: 10

PostPosted: Wed Apr 26, 2006 11:34 am   
 
It will take a little time before I can do this. My scripts are fairly complex. Within the next couple of days I will do this. My workaround is working nicely though.

Thanks for taking the time to look into my question. I appreciate it.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot 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

© 2009 Zugg Software. Hosted by Wolfpaw.net