|
Jaiven Wanderer
Joined: 03 Oct 2007 Posts: 66
|
Posted: Sat Jun 30, 2012 4:00 am
Oh boy here is a hard one... |
Random Dir Script conversion from Zmud to Cmud for a random zone. It works in cmud but it keeps going back and forth from the same room to the other over and over again.
Trigger:^(*)~[ Exits:(*)~]$
Value:
#VAR ExitsStr {%2}
#VAR ArrayExits {%replace( @ExitsStr, ' ', '|')}
#var TotalDirs %numitems( @ArrayExits)
#if (@AutoRunner=1) {
#var Mobs 0
#var NewRoom 1
#T+ @Place
#var GetRusted 1
}
#if (@AutoNim=1) {
#var Mobs 0
#var NewRoom 1
#T+ @Place
}
#if (@AutoAbyss=1) {
#var Mobs 0
#var NewRoom 1
#T+ @Place
#if @NimDir=up) {
#var ArrayExits %delitem( down, @ArrayExits)
#ADD TotalDirs -1
}
#if @NimDir=down) {
#var ArrayExits %delitem( up, @ArrayExits)
#ADD TotalDirs -1
}
#if @NimDir=east) {
#var ArrayExits %delitem( west, @ArrayExits)
#ADD TotalDirs -1
}
#if @NimDir=west) {
#var ArrayExits %delitem( east, @ArrayExits)
#ADD TotalDirs -1
}
#if @NimDir=south) {
#var ArrayExits %delitem( north, @ArrayExits)
#ADD TotalDirs -1
}
#if @NimDir=north) {
#var ArrayExits %delitem( south, @ArrayExits)
#ADD TotalDirs -1
}
#if (@TotalDirs=0) {#var NimDir @PrevNimDir}
}
Trigger: ^~[Rep:*~]~[Gold:(%d)~]~[xp:(%n)~]~[(%n)~] ~[*~]->$
Value
#if (@AutoNim=1) {#if (@NewRoom=1) {
#var NewRoom 0
#if (@Total_mobs=0) {godir}
#if (@Total_mobs>0) {
#var target %item( @Mob_Array, 1)
gg
}
}}
#if (@AutoAbyss=1) {
#if (%2=1000000000) {halt}
#if (@NewRoom=1) {
#var NimDir %item( @ArrayExits, %random( 1, @TotalDirs))
#var NewRoom 0
#if (@Total_mobs=0) {
@nimdir
#var Mob-Array {}
}
#if (@Total_mobs>0) {
#var target %item( @Mob_Array, 1)
gg
}
}
}
In one of those trigs somewhere it is messing it up and I am at a complete loss.
Edit: I also had it so it would remove the last direction when it randoms the direction again so I wouldn't repeat rooms... Doesn't do that in cmud |
|
|
|
charneus Wizard
Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Sat Jun 30, 2012 7:33 am |
A few things to mention:
1. Please, whenever posting code, put it between [code][/code] tags (e.g. [code]<put code here>[/code]). It makes it slightly easier to read. Even better is if you right-click the trigger in CMUD, choose copy, then paste that info between the code tags. That way we can just copy/paste into our own CMUD.
2. You don't need to capture everything, especially if you're not using it. Your first trigger, you can remove the () around the first *. You're not using it in the value at all.
3. You don't need to name a variable to something you're using within the code and won't use elsewhere. In your first trigger, you create (or update a variable) called ExitStr. You don't seem to use it anywhere else, so that line isn't needed at all.
4. Instead of using %replace(%1, ' ', '|'), you can use %list(%1," ").
5. You don't need to do var=1 or var>0 if you're checking for true/false. Doing #IF (@var) {true} {false} will return true each time @var is not equal to 0. Doing #IF (!@var) {true} {false} will return true each time @var IS equal to 0.
6. You really should have double quotes around strings so CMUD knows it's nothing other than a string. Things like #IF (@NimDir=up) should be #IF (@NimDir="up") Please note this does not apply to numbers.
7. If you have multiple #IFs and you're doing at least one thing the same in each, you don't have to process it for each #IF. If you put it at the end of the multiple #IFs, it'll process properly. Example:
Code: |
#IF (@A) {command 1;command 2};#IF (@B) {command 3;command 2};#IF (@C) {command 4;command 2} |
can be changed to:
Code: |
#IF (@A) {command 1};#IF (@B) {command 3};#IF (@C) {command 4};command 2 |
8. You can change the #IF (@NimDir=blah) into one #SWITCH. Here's how you would do this one:
Code: |
#SWITCH (@NimDir) ("up") {ArrayExits=%delitem("down",ArrayExits)} ("down") {ArrayExits=%delitem("up",ArrayExits)} ("east") {ArrayExits=%delitem("west",ArrayExits)} ("west") {ArrayExits=%delitem("east", ArrayExits)} ("north") {ArrayExits=%delitem("south", ArrayExits)} ("south") {ArrayExits=%delitem("north",ArrayExits)};TotalDirs=%numitems(ArrayExits) |
Please note that you no longer have to include the @ in most functions when you're using a variable. As written above, it should work. If it doesn't, place the @ in front of the ArrayExits in the %delitem function.
9. CMUD does not know what to do when a command starts out with a function or a variable. Instead, we must now include an actual command for CMUD to follow to execute variables. In the line where you have @nimdir by itself, you need to change that to #EXEC @nimdir. If you ever need to run a function on a variable, you would use #CALL %function instead.
These are immediate things I can spot right now that would help improve your code. It may not make your code work, but it'll go a long way to getting someone to be able to get it to work. Repost with the suggestions I've made, and it might be easier for us to work with. |
|
|
|
Jaiven Wanderer
Joined: 03 Oct 2007 Posts: 66
|
Posted: Sat Jun 30, 2012 12:20 pm |
Thank you and sorry it is so messy and confusing. This is just stuff I learned on my own, as a kid, and 10+ years later I'm now asking for help because I converted to cmud. I must look like a savage which was raised by scripting wolves lol. ^.^
|
|
|
|
Jaiven Wanderer
Joined: 03 Oct 2007 Posts: 66
|
Posted: Sat Jun 30, 2012 1:54 pm |
Ok, I got the list working and the #switch working so thank you very much. It is now correctly loading the dirs into the script and randomly choosing one to move onto the next part. What is messed up now is that I used to use this %of wjem there were no mobs so I hope I pasted this correct this time.
Code: |
<alias name="NoMobs" id="282">
<value>#if (@Autorunner=1) {
#var corpse_total 0
#var Mobs 0
#var Mob_Array {}
#var Total_Mobs 0
#if (@AutoAbyss!=1) {godir}
}
#if (@AutoAbyss=1) {
spellup
%if( @TotalDirs=0, @PrevNimDir, @nimdir)
}
#if @AutoNim=1) {
#var corpse_total 0
#var Mobs 0
Spellup
#var Mob_Array {}
#var Total_Mobs 0
}</value>
</alias>
|
this %if is what is messing it up I believe since it is in red or pink in the script txt |
|
|
|
Jaiven Wanderer
Joined: 03 Oct 2007 Posts: 66
|
Posted: Sat Jun 30, 2012 2:00 pm |
Code: |
<trigger priority="50" id="430">
<pattern>^~[Rep:*~]~[Gold:(%d)~]~[xp:(%n)~]~[(%n)~] ~[*~]->$</pattern>
<value>#var MyGold {%1}
#var MyExp {%2}
#var Align {%3}
#if (@AutoRunner=1) {#if (@NewRoom=1) {
#var NewRoom 0
#if (@Total_mobs=0) {
spellup
godir
}
#if (@Total_mobs>0) {
#var target %item( @Mob_Array, 1)
gg
}
}}
#if (@AutoNim=1) {#if (@NewRoom=1) {
#var NewRoom 0
#if (@Total_mobs=0) {godir}
#if (@Total_mobs>0) {
#var target %item( @Mob_Array, 1)
gg
}
}}
#if (@AutoAbyss=1) {
#if (%2=1000000000) {halt}
#if (@NewRoom=1) {
#var NimDir %item( @ArrayExits, %random( 1, @TotalDirs))
#var NewRoom 0
#if (@Total_mobs=0) {
@nimdir
#var Mob-Array {}
}
#if (@Total_mobs>0) {
#var target %item( @Mob_Array, 1)
gg
}
}
}</value>
</trigger>
|
I also don't think it is doing the %random or %item correctly either. |
|
|
|
charneus Wizard
Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Sat Jun 30, 2012 4:10 pm |
As I mentioned in point 9 (though I should have worded it better), CMUD does not understand what to do when a line starts with a function or a variable. In the case of the %if function, you need to change it to:
Code: |
#EXEC %if( @TotalDirs=0, @PrevNimDir, @nimdir) |
Additionally, as I told you before, if you're only checking for "true/false", then you don't need the = or >. This:
Code: |
#if (@Total_mobs=0) {godir}
#if (@Total_mobs>0) {
#var target %item( @Mob_Array, 1)
gg
} |
could be cleaned up to read:
Code: |
#IF (@Total_mobs) {target=%item(Mob_Array, 1);gg} {godir} |
You actually should change all variations to the format listed above.
When you simplify things, it makes it easier to tell where the problem is (for both yourself and anyone looking at the code). And by the way, the %if turned pink because CMUD defaults to pretty printing, which colorizes certain text a certain color, depending on what it does. Variables are blue, functions are pink, commands are bold black, etc. |
|
|
|
Jaiven Wanderer
Joined: 03 Oct 2007 Posts: 66
|
Posted: Sat Jun 30, 2012 6:04 pm |
Ok, I got it almost working now but the nimdir sometimes doesn't load properly (and has no value) and sometimes it does load properly. I am not sure why though and if I just type look again it loads it and works.. I believe this would be because of my exit or reply triggers? Let me know if anyone sees what is going wrong and I'm sorry I am not as good as this as you guys. You are all a huge help though. I also noticed totaldirs isn't adding right. I have The Abyss [ exits: north east south west down ] and it adds 6 to totaldirs not 5
Code: |
<trigger priority="40" id="2540">
<pattern>^*~[ exits:(*)~]$</pattern>
<value>#VAR ExitsStr {%1}
#VAR ArrayExits {%list(%1," ")}
#var TotalDirs %numitems( @ArrayExits)
#if (@AutoRunner=1) {
#var Mobs 0
#var NewRoom 1
#T+ @Place
#var GetRusted 1
}
#if (@AutoNim=1) {
#var Mobs 0
#var NewRoom 1
#T+ @Place
}
#if (@AutoAbyss=1) {
#var Mobs 0
#var NewRoom 1
#T+ @Place
#SWITCH (@NimDir) ("up") {ArrayExits=%delitem("down",ArrayExits)} ("down") {ArrayExits=%delitem("up",ArrayExits)} ("east") {ArrayExits=%delitem("west",ArrayExits)} ("west") {ArrayExits=%delitem("east", ArrayExits)} ("north") {ArrayExits=%delitem("south", ArrayExits)} ("south") {ArrayExits=%delitem("north",ArrayExits)};TotalDirs=%numitems(ArrayExits)}</value>
</trigger>
|
Code: |
<trigger priority="50" id="2541">
<pattern>^~[Rep:*~]~[Gold:(%d)~]~[xp:(%n)~]~[(%n)~] ~[*~]->$</pattern>
<value>#var MyGold {%1}
#var MyExp {%2}
#var Align {%3}
#if (@AutoRunner=1) {#if (@NewRoom=1) {
#var NewRoom 0
#if (@Total_mobs=0) {
spellup
godir
}
#if (@Total_mobs>0) {
#var target %item( @Mob_Array, 1)
gg
}
}}
#if (@AutoNim=1) {#if (@NewRoom=1) {
#var NewRoom 0
#If (@Total_mobs) {
target=%item( Mob_Array, 1)
gg
} {godir}}}
#if (@AutoAbyss=1) {
#if (%2=1000000000) {halt}
#if (@NewRoom=1) {
#var NimDir %item( @ArrayExits, %random( 1, @TotalDirs))
#var NewRoom 0
#if (@Total_mobs=0) {
@nimdir
#var Mob-Array {}
}
#if (@Total_mobs>0) {
#var target %item( @Mob_Array, 1)
gg
}
}
}</value>
</trigger>
|
|
|
|
|
Jaiven Wanderer
Joined: 03 Oct 2007 Posts: 66
|
Posted: Sat Jun 30, 2012 6:09 pm |
Hmmm, so I noticed when it moves to a room with 3 exits it sets totaldirs as 4. Now it should be 2 totals dirs because 3 -1 (prevdir so I don't backtrack in my random dir zone) should be 2 not 4. So, if it then randomly chooses from 4 then 2 of those would be dirs that don't exist right? I'm thinking that is what isn't working right maybe... I don't know... it all worked perfectly in zmud lol but I love cmud now =/
|
|
|
|
Jaiven Wanderer
Joined: 03 Oct 2007 Posts: 66
|
Posted: Sat Jun 30, 2012 11:41 pm |
anyone? Also, if anyone has the time (probably an hour or less) and wants to assist with this on an IM program or Vent just PM me. My friend and I have been working on it all day and it seems the nimdir is adding too much to its value and not the correct amount of exits. We can't figure it out for the life of us. =/
|
|
|
|
charneus Wizard
Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Sun Jul 01, 2012 12:46 am |
Where are you originally defining @NimDir? That doesn't appear to be listed anywhere here. Also, you might consider adding #PRINT {@NimDir} as debugging to see what's actually being stored.
|
|
|
|
Jaiven Wanderer
Joined: 03 Oct 2007 Posts: 66
|
Posted: Sun Jul 01, 2012 1:10 am |
Yup, we did that and figured out the problem and can't find a solution so here it is!
lets say there are three rooms. it is assigning those 3 rooms to an array (arrayexits) but adds two more null values (when we check arrayexits it will have 1 (nothing 2 south 3 north 4 nothing and so forth. it seems when it randomly assigns arrayexits to nimdir it sometimes chooses that null value from arrayexits. to answer your questions arrayexits is assigned to nimdir here
Code: |
<trigger priority="50" id="2541">
<pattern>^~[Rep:*~]~[Gold:(%d)~]~[xp:(%n)~]~[(%n)~] ~[*~]->$</pattern>
<value>#var MyGold {%1}
#var MyExp {%2}
#var Align {%3}
#if (@AutoRunner=1) {#if (@NewRoom=1) {
#var NewRoom 0
#if (@Total_mobs=0) {
spellup
godir
}
#if (@Total_mobs>0) {
#var target %item( @Mob_Array, 1)
gg
}
}}
#if (@AutoNim=1) {#if (@NewRoom=1) {
#var NewRoom 0
#If (@Total_mobs) {
target=%item( Mob_Array, 1)
gg
} {godir}}}
#if (@AutoAbyss=1) {
#if (%2=1000000000) {halt}
#if (@NewRoom=1) {
#var NimDir %item( @ArrayExits, %random( 1, @TotalDirs))
#var NewRoom 0
#if (@Total_mobs=0) {
@nimdir
#var Mob-Array {}
}
#if (@Total_mobs>0) {
#var target %item( @Mob_Array, 1)
gg
}
}
}
#show @nimdir
#show @arrayexits</value>
</trigger>
|
it is in the reply script which i just posted but arrayexits is being assigned too many values from exits and we don't know why!
Code: |
<trigger priority="40" id="2540">
<pattern>^*~[ exits:(*)~]$</pattern>
<value>#VAR ExitsStr {%1}
#VAR ArrayExits {%list(%1," ")}
#var TotalDirs %numitems(@ArrayExits)
#if (@AutoRunner=1) {
#var Mobs 0
#var NewRoom 1
#T+ @Place
#var GetRusted 1
}
#if (@AutoNim=1) {
#var Mobs 0
#var NewRoom 1
#T+ @Place
}
#if (@AutoAbyss=1) {
#var Mobs 0
#var NewRoom 1
#T+ @Place
#SWITCH (@NimDir) ("up") {ArrayExits=%delitem("down",ArrayExits)} ("down") {ArrayExits=%delitem("up",ArrayExits)} ("east") {ArrayExits=%delitem("west",ArrayExits)} ("west") {ArrayExits=%delitem("east",ArrayExits)} ("north") {ArrayExits=%delitem("south",ArrayExits)} ("south") {ArrayExits=%delitem("north",ArrayExits);TotalDirs=%numitems(ArrayExits)}}</value>
</trigger>
|
that is exits |
|
|
|
charneus Wizard
Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Sun Jul 01, 2012 1:17 am |
I think I see your problem.
I'm going to guess that your exits line looks like this:
Code: |
blah blah blah [ exits: north south east ] |
The code is doing exactly what it should be doing, and that's creating a list out of %1 using a space as a delimiter. In this case, %1 is being defined as: " north south east ". So CMUD makes it a list and sets: "|north|south|east|" because of the first and last space.
Therefore, I suggest you change exits:(*)~] to exits: (*) ~].
That should fix your problem. |
|
|
|
Jaiven Wanderer
Joined: 03 Oct 2007 Posts: 66
|
Posted: Sun Jul 01, 2012 1:32 am |
THANK YOU SO MUCH!!! IT WORKS!
|
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Sun Jul 01, 2012 9:05 pm |
Alternatively, you could use the %trim() function to get rid of all leading and trailing spaces, or change
to
to cause the %list function to drop any null values. |
|
|
|
|
|
|
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
|
|