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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD Beta Forum
darmir
Sorcerer


Joined: 10 Oct 2000
Posts: 706
Location: USA

PostPosted: Mon Oct 15, 2007 8:43 pm   

[2.06] cMUDPRO - Variable not setting correctly
 
<cmud>
<alias name="fgrubs">
<value>
//pmote working next to an empty wooden cart.
#variable grcount ""
#variable totalgrubs ""
#variable totalgrubs %1
#SHOW You will now gather upto @totalgrubs grubs.
#T+ findgrubs
find grubs
</value>
</alias>
</cmud>

<cmud>
<trigger name="findgrubs" priority="7220">
<pattern>
You turn over some rocks and boulders trying your hardest to find a grub.
</pattern>
<value>
#CASE %random {
sweat
} {
emote moves some twigs near the rocks looking for a grub.
} {
emote stretches a little, cracking his back.
} {
emote wipes the dirt on his pants and goes back to looking for a grub.
} {
emote takes a deep sigh and continues to search around for a grub.
} {
emote momentarily stops searching for grubs to scratch his nose.
} {
emote looks up from searching the area for grubs.
} {
#echo NO MESSAGE TO MUD
}
</value>
<trigger>
<pattern>You find a pale white grub beneath a rock. </pattern>
<value>look
</value>
</trigger>
<trigger>
<pattern>A pale white grub wriggles upon the ground. </pattern>
<value>
//#show @grcount
#MATH grcount @grcount+1
//#show @grcount
//#show @totalgrubs
#SHOW You have @grcount grub~(s~) of @totalgrubs.
#ALARM {+5} {
#IF (@grcount == @totalgrubs) {
#T- find-grubs
#ALARM {+5} {get grub}
#ALARM {+10} {put grub cart}
#ALARM {+15} {#show You have gotten all @totalgrubs grub~(s~).}
#var grcount ""
#var totalgrubs ""
} {
#ALARM {+5} {get grub}
#ALARM {+10} {put grub cart}
#ALARM {+15} {find grubs}
}
}
</value>
</trigger>
</trigger>
</cmud>

Sometimes when I run my alias the variables don't get reset.
_________________
Run as hard as a wild beast if you will, but you won't get any reward greater than that destined for you.
Source: (Egyptian)

Last edited by darmir on Mon Oct 15, 2007 10:45 pm; edited 2 times in total
Reply with quote
darmir
Sorcerer


Joined: 10 Oct 2000
Posts: 706
Location: USA

PostPosted: Mon Oct 15, 2007 8:45 pm   
 
Example output from mud.


fgrubs 53
You will now gather upto 53 grubs.
find grubs
You carefully search the bank of a small shallow pond.

<****** / ||||||>
You turn over some rocks and boulders trying your hardest to find a grub.
emote takes a deep sigh and continues to search around for a grub.

<****** / ||||||> A dark-skinned, brown-eyed man takes a deep sigh and continues to search
around for a grub.

<****** / ||||||>
You find a pale white grub beneath a rock.
look

<****** / ||||||> East of a Stream and Lake in the Fields
Exits: north east south west

Fertile soil gives growth to a multitude of things in the
Pelennor Fields, to the green grass on the hills and fallows
fields, to the numerous crops of wheat, barley, beans and other
such things and to the grazing land for the herds of cattle and
sheep that occupy the Fields. As they expand outwards in all
directions, contained only by the Mount Mindolluin to the west
and the Rammas Echor that forms their boundaries, the Pelennor
Fields contain within them much of the agricultural production
for Northern Gondor and the city Minas Tirith.
Westwards lies a small lake in the fields, while all other
directions leads on to more farmland.

A small shallow pond surrounded with reeds is here.
A two-wheeled, wooden push-cart is here.
A pale white grub wriggles upon the ground.
You have 1 grub(s) of 53.

<****** / ||||||> get grub
You get a pale white grub.

<****** / ||||||> put grub cart
You put a pale white grub into a wooden push-cart.

<****** / ||||||> You have gotten all grub(s).
_________________
Run as hard as a wild beast if you will, but you won't get any reward greater than that destined for you.
Source: (Egyptian)
Reply with quote
Seb
Wizard


Joined: 14 Aug 2004
Posts: 1269

PostPosted: Mon Oct 15, 2007 9:14 pm   
 
Which version of CMUD?
Reply with quote
darmir
Sorcerer


Joined: 10 Oct 2000
Posts: 706
Location: USA

PostPosted: Mon Oct 15, 2007 9:17 pm   
 
Oops. I thought I put that in the subject. cMUDPro 2.05
_________________
Run as hard as a wild beast if you will, but you won't get any reward greater than that destined for you.
Source: (Egyptian)
Reply with quote
Seb
Wizard


Joined: 14 Aug 2004
Posts: 1269

PostPosted: Mon Oct 15, 2007 9:53 pm   
 
I think you should try again with 2.06 as several threading related problems were fixed and that could have caused intermittent and unpredictable problems.
Reply with quote
darmir
Sorcerer


Joined: 10 Oct 2000
Posts: 706
Location: USA

PostPosted: Mon Oct 15, 2007 10:44 pm   
 
I get the same issue with 2.06.. I am going to update the title above to v2.06
_________________
Run as hard as a wild beast if you will, but you won't get any reward greater than that destined for you.
Source: (Egyptian)
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Mon Oct 15, 2007 11:29 pm   
 
Quote:
Sometimes when I run my alias the variables don't get reset.

Exactly which variables are not getting reset. I need more details on exactly what it is supposed to do, and what it isn't doing.

You are also not initializing some of your variables correctly. You have stuff like this:

#variable grcount ""

That initializes the variable to the blank literal string value. And if you then do

#MATH grcount @grcount+1

then the + operator becomes a string "concat" operator and you end up with strings like "123" as you keep concating a new number to the string. You should always initialize numeric variables to zero and not "".

Also, using "#ADD grcount 1" is a lot more efficient than using #MATH for this, and #ADD is also threadsafe.

Next, you have a line like this:

#T- find-grubs

You cannot have - characters in the names of anything (variables, classes, anything). This is true in most programming languages. You can use the _ character instead of - if you want. Otherwise CMUD is going to try and subtract two strings, which doesn't make any sense. If you *must* use the - character, then you must always put " quotes around the name.

Also, you are not consistent. In some places you use "findgrubs" and in other places you have "find-grubs".

Also, your use of #alarms is really a bad idea. Alarms in CMUD fire in parallel, and if your +5 alarm somehow takes more than 5 seconds to run, then the +10 alarm might execute first. If you want to send commands to the MUD sequentially, you should use the #WAIT command, which works now in v2.0x.

For example, just do this:

Code:
get grub
#WAIT 5000
put grub cart
#WAIT 5000
find grubs

That will ensure that there is a 5 second delay between each command.

Anyway, those were the problems that I initially saw in your script. You need to keep in mind that CMUD is a *lot* pickier about requiring correct script syntax than zMUD was. Just because something worked in zMUD doesn't mean that it was correct. zMUD just had a lot of loopholes where syntax problems were ignored.
Reply with quote
darmir
Sorcerer


Joined: 10 Oct 2000
Posts: 706
Location: USA

PostPosted: Tue Oct 16, 2007 12:51 am   
 
Zugg,
The totalgrubs variable doesn't give me the correct number.


That is weird. Because I used findgrubs everywhere. I don't know why it is showing up as find-grubs.

As for initializing the variables, is it different now in cMUD. I used to initialize them with #var variable_name "".

I also thought is was always said to NOT use the wait command and always try to use alarms.
_________________
Run as hard as a wild beast if you will, but you won't get any reward greater than that destined for you.
Source: (Egyptian)
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Tue Oct 16, 2007 12:57 am   
 
Well, you are only resetting totalgrubs when

#IF (@grcount == @totalgrubs) {

So, if your #MATH for @grcount gets messed up because of using "" to initialize it, then this #IF statement will always fail and it will not reset your variables.

Quote:
As for initializing the variables, is it different now in cMUD. I used to initialize them with #var variable_name "".

Yes, that is correct. It *IS* different in CMUD. Variables types are more important in CMUD than in zMUD.

Quote:
I also thought is was always said to NOT use the wait command and always try to use alarms.

That was true in zMUD and in the 1.x versions of CMUD, but it is not the case in v2.x of CMUD. v2.x was specifically improved to make the #WAIT command work and to add other related #WAIT commands.

Quote:
I don't know why it is showing up as find-grubs.

Sounds like you just made a typo somewhere. In the Package Editor you can use the Find menu command and enter find-grubs into the search bar and it will display any setting that uses that so that you can change it.
Reply with quote
darmir
Sorcerer


Joined: 10 Oct 2000
Posts: 706
Location: USA

PostPosted: Tue Oct 16, 2007 1:08 am   
 
Okay.
I initiallized the variables differently they are now
#variable grcount 0
#variable totalgrubs 0

I also change the alarms to waits as per the suggestion from Zugg. I also fixed my dash problem. And the totalgrubs variable isn't correct and I still get the same issue I did before.
_________________
Run as hard as a wild beast if you will, but you won't get any reward greater than that destined for you.
Source: (Egyptian)
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Tue Oct 16, 2007 7:41 pm   
 
OK, well, looking at your script some more, you have this:
Code:
#IF (@grcount == @totalgrubs) {
  #T- findgrubs
  #ALARM {+5} {get grub}
  #ALARM {+10} {put grub cart}
  #ALARM {+15} {#show You have gotten all @totalgrubs grub~(s~).}
  #var grcount 0
  #var totalgrubs 0
}

That is going to clear "totalgrubs" *before* any of your alarms run. So when your alarm +15 runs, @totalgrubs is going to be zero all the time. You might want to post the full version of your new script to see if there are other problems still.
Reply with quote
darmir
Sorcerer


Joined: 10 Oct 2000
Posts: 706
Location: USA

PostPosted: Wed Oct 17, 2007 6:46 pm   
 
Code:
alias:

<?xml version="1.0" encoding="UTF-8" ?>
<cmud>
  <alias name="fgrubs">
    <value>//pmote working next to an empty wooden cart.
#variable grcount 0
#variable totalgrubs  0
#variable totalgrubs %1
#SHOW You will now gather upto @totalgrubs grubs.
#T+ findgrubs
find grubs</value>
  </alias>
</cmud>


Trigger:


<?xml version="1.0" encoding="UTF-8" ?>
<cmud>
  <trigger name="findgrubs" priority="7220">
    <pattern>You turn over some rocks and boulders trying your hardest to find a grub. </pattern>
    <value>#CASE %random {
sweat
} {
emote moves some twigs near the rocks looking for a grub.
} {
emote stretches a little, cracking his back.
} {
emote wipes the dirt on his pants and goes back to looking for a grub.
} {
emote takes a deep sigh and continues to search around for a grub.
} {
emote momentarily stops searching for grubs to scratch his nose.
} {
emote looks up from searching the area for grubs.
} {
#echo NO MESSAGE TO MUD
} </value>
    <trigger>
      <pattern>You find a pale white grub beneath a rock. </pattern>
      <value>look
</value>
    </trigger>
    <trigger>
      <pattern>A pale white grub wriggles upon the ground. </pattern>
      <value>//#show @grcount
#ADD grcount 1
//#show @grcount
//#show @totalgrubs
#SHOW You have @grcount grub~(s~) of @totalgrubs.
#IF (@grcount == @totalgrubs) {
    #T- findgrubs
    #WAIT 5000
    get grub
    #WAIT 5000
    put grub cart
    #WAIT 5000
    #show You have gotten all @totalgrubs grub~(s~).
    #var grcount ""
    #var totalgrubs ""
    }  {
    get grub
    #WAIT 5000
    put grub cart
    #WAIT 5000
    find grubs
  }</value>
    </trigger>
  </trigger>
</cmud>
_________________
Run as hard as a wild beast if you will, but you won't get any reward greater than that destined for you.
Source: (Egyptian)

Last edited by darmir on Wed Oct 17, 2007 7:02 pm; edited 1 time in total
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Wed Oct 17, 2007 6:51 pm   
 
I added a code tag to make your post a bit more readable.

You're still using "" to set the grcount and totalgrubs variables in the trigger.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
darmir
Sorcerer


Joined: 10 Oct 2000
Posts: 706
Location: USA

PostPosted: Wed Oct 17, 2007 6:53 pm   
 
OOPs. I thought I fixed that.
_________________
Run as hard as a wild beast if you will, but you won't get any reward greater than that destined for you.
Source: (Egyptian)
Reply with quote
darmir
Sorcerer


Joined: 10 Oct 2000
Posts: 706
Location: USA

PostPosted: Wed Oct 17, 2007 6:57 pm   
 
I have modified my trigger above and I now I get the zero for my total.

It gives me:

Code:

<****** / ||||||> fgrub s 6
I don't recognize that command.

<****** / ||||||> You will now gather upto 6 grubs.
find grubs
You carefully search the bank of the clear water of the babbling
brook.

<****** / ||||||>
You turn over some rocks and boulders trying your hardest to find a grub.
emote moves some twigs near the rocks looking for a grub.

<****** / ||||||> A dark-skinned, brown-eyed man moves some twigs near the rocks looking for
a grub.

<****** / ||||||>
You find a pale white grub beneath a rock.
look

<****** / ||||||> A Small Pond in the Pelennor Fields
Exits: north east south west

   The Pelennor Fields stretch out in all directions here,
covering the entire countryside between the colossal Mount
Mindolluin and the Rammas Echor. Far from being one single, flat
plain, the Pelennor Fields contain within them cool dams and
small bubbling streams, hillocks and mounds, great fields and
short-growing grazing land. The occasional farmstead can be seen
among the Fields, as well as wagons and carts making their way
across the three roads that cross the landscape, bearing
travellers and goods from all about Gondor.
   From the west a babbling brook flows, filling a small,
circular pond and providing life for the water reeds that grow
upon its sandy shore.

A log cabin has been built in a clearing.
The clear water of the babbling brook flows here.
A small shallow pond surrounded with reeds is here.
Leafy green stalks sprout here, topped with yellow-centered white blossoms.
A pale white grub wriggles upon the ground.
You have 1 grub(s) of 6.

<****** / ||||||> get grub
You get a pale white grub
put
<****** / ||||||> put grub cart
You put a pale white grub into a wooden push-cart.

<****** / ||||||> You have gotten all 0 grub(s).

_________________
Run as hard as a wild beast if you will, but you won't get any reward greater than that destined for you.
Source: (Egyptian)
Reply with quote
Seb
Wizard


Joined: 14 Aug 2004
Posts: 1269

PostPosted: Thu Oct 18, 2007 12:13 am   
 
My suggestion is to break down the script until you can get it to work (or find a bug). You can test it offline using the #SHOW command. e.g.
Code:
#SHOW A pale white grub wriggles upon the ground.
(note the trailing space)

Another thing to check is the type of the variables. You may want to set them to integers instead of autotype.
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Thu Oct 18, 2007 12:44 am   
 
OK, I finally took the time to create a new session, entered your script, and tested it myself. And it worked fine for me here. So my guess is that you have something else somewhere else in your settings that is interfering with this script. When your script shown above is the only thing in a file then it works. You might want to search for any other setting that accesses the totalgrubs or grcount variables.

Changing the type to integers won't make any difference.
Reply with quote
darmir
Sorcerer


Joined: 10 Oct 2000
Posts: 706
Location: USA

PostPosted: Thu Oct 18, 2007 1:46 am   
 
Zugg,
That is the only script I have setup using those variables. This was a brand new installation of cMUDPro and this is the only script I have written
_________________
Run as hard as a wild beast if you will, but you won't get any reward greater than that destined for you.
Source: (Egyptian)
Reply with quote
Seb
Wizard


Joined: 14 Aug 2004
Posts: 1269

PostPosted: Thu Oct 18, 2007 2:20 am   
 
Well start with a new session then.
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Fri Oct 19, 2007 12:13 am   
 
It's possible that I just had a similar problem myself. I had a script that does:
Code:
varname = 0
#SHOW @varname

and when I first connected to the MUD and used it the first time, it displayed '1' instead of '0'. The value saved in the pkg file was '1', so somehow it wasn't getting set. I'm having a hard time reproducing this, but I will continue trying to track it down.

This is a bit different from yours, because it only fails the first time I run it, and then it works fine after that.
Reply with quote
darmir
Sorcerer


Joined: 10 Oct 2000
Posts: 706
Location: USA

PostPosted: Mon Oct 22, 2007 7:09 pm   
 
Well I am not sure what is going on here. It seems to fix the totalgrubs issue, but now my grcount variable isn't working.

It gives me the correct count but when I look at the grcount variable through the setting it isn't being added. And the if statement is finding it.

The weird thing is the show statement says the grcount is growing. :(


Update: I opened a new session and it seems to fix it for awhile but then it eventually stops working.
_________________
Run as hard as a wild beast if you will, but you won't get any reward greater than that destined for you.
Source: (Egyptian)
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Mon Oct 22, 2007 8:21 pm   
 
Make sure to update to v2.07 and see if it still happens there. The bug that was causing my own problem with variables is fixed in 2.07.

If you are already talking about 2.07, then try unselecting the View/Group by Class option in the settings editor to see all of your variables no matter what class they are in. My guess is that your grcount variable got created in some subclass somewhere.
Reply with quote
darmir
Sorcerer


Joined: 10 Oct 2000
Posts: 706
Location: USA

PostPosted: Mon Oct 22, 2007 9:45 pm   
 
Darn.. I thought I put the version in the last post. I did upgrade to 2.07 which fixed the initialization issue of totalgrubs variable
_________________
Run as hard as a wild beast if you will, but you won't get any reward greater than that destined for you.
Source: (Egyptian)
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD Beta Forum 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