|
wrym Magician
Joined: 06 Jul 2007 Posts: 349 Location: The big palace, My own lil world
|
Posted: Wed Apr 15, 2009 4:26 pm
something funky with this alias... |
I have an alias, chant, that checks my position, and stands me/returns to previous position if i'm not standing.
Code: |
#if (@position != "Standing") {
#local $position;
$position = @position;
stand;
\chant %params;
#execute %leftback($position,4);
} {
\chant %params
}
#print chant alias |
I'm using \chant to prevent recursive calls, my mud strips out leading \.
My problem is this, assuming @position == meditating, this is what gets sent to the mud:
Code: |
2
\3 kere drva vant ex
Medita
chant alias |
If I use ~chant I get this
Code: |
2
c3 kere drva vant ex
Medita
chant alias |
I have tried using #send, but then i start getting invalid parameter errors with ctrl+k. I've also restarted cmud, deleted the alias, and re made it, adjusted spacing, used semicolons at end of lines and without.
stand and chant are highlighted in blue in the true portion of the #if, but chant in the false is, plain black. i do NOT have any stand aliases/varibles, other chant aliases, or varibles.
If i'm doing something stupid I cant see it. Anyone have any suggestions? |
|
|
|
charneus Wizard
Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Wed Apr 15, 2009 5:28 pm |
First of all, I don't see why you're calling a local variable only to have it set to the position variable anyway. You're better off just using the @position. In fact, looking at the script in script editor, it appears that you putting the $postion=@position is the reason why it's not working.
Changing it to:
Code: |
#if (@position != "Standing") {
stand
\chant %params
#execute %leftback( @position, 4)
} {\chant %params}
#print chant alias |
Shows no errors on my end. I'm assuming you're using \ as an escape, correct?
Charneus |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Wed Apr 15, 2009 5:32 pm |
The proper way to prevent recursive calls is to use the ~ character in CMUD. So unless you have changed the ~ to \ in the Special Character preferences, you should just do:
~chant %params
That should take care of your syntax errors. |
|
|
|
wrym Magician
Joined: 06 Jul 2007 Posts: 349 Location: The big palace, My own lil world
|
Posted: Wed Apr 15, 2009 5:48 pm |
Ahh, well now that i look at it i don't need to assign a temporary state for the position, BUT that still shouldn't have given me an error.
That being said, using $pos also gave same problems. As i was remarking out the #local the highlighting changed and I tried this:
Code: |
#if (@position != "Standing") {
//#local $pos
$pos = @position
stand
\chant %params
#execute %leftback($pos,4)
} {
\chant %params
} |
Which doesn't give an error, and does work.
Zugg, I did try the ~, but it just gave further anomalies. At that point I starting using the mud's anti-recursive alias \ |
|
|
|
charneus Wizard
Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Wed Apr 15, 2009 6:23 pm |
If you insist on using the local variable, it will always give an error when doing @position.
The correct way of doing that would be to change it to the proper format of:
$pos=@{postion}
But again, there is no need whatsoever for you to use a local variable in here. You're just taking that much more time to compile the script. Not sure about using the MUD's anti-recursive alias, but give it a try.
Charneus |
|
|
|
wrym Magician
Joined: 06 Jul 2007 Posts: 349 Location: The big palace, My own lil world
|
Posted: Wed Apr 15, 2009 6:49 pm |
I've already remarked out the code, I don't' delete, just remark it out usually, and noticed this while I was removing the local variables.
I was unaware that when assigning a value to a local from a global variable you need to use the $local=@{global} syntax. That removed the error when I tested it.
Perhaps this should be added to the local variables help page?
Also the #local link on this page
http://forums.zuggsoft.com/modules/mx_kb/kb.php?page=3&mode=doc&k=2742
leads to #location |
|
_________________ "To the engineer, all matter in the universe can be placed into one of two categories: (1) things that need to be fixed, and (2) things that will need to be fixed after you've had a few minutes to play with them" - Scott Adams, The Dilbert Principle |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Thu Apr 16, 2009 5:05 pm |
No, no, you don't need the $pos=@{postion} syntax. The $local=@varname syntax works fine. So let's not get everyone confused on this.
I tried the original script, and there does seem to be a nasty compiler bug in there somewhere. The $position=@position is actually working, but it is causing the following line to be parsed incorrectly if it isn't a command. For example, if you move the "stand" and "~chant %params" *after* the #EXECUTE line, then it works correctly.
The correct *syntax* for your script should be this:
Code: |
#if (@position != "Standing") {
$position = @position
stand
~chant %params
#execute %leftback($position,4)
} {
~chant %params
}
#print chant alias |
You don't need the #LOCAL statement since the $position=@position assignment creates the local variable within the current scope already. You would only need the #LOCAL command if you wanted to do it *before* the #IF statement and have the $position variable available outside of the #IF statement. Also, you don't need the ; at the end of each line. The ; is only for separating multiple commands on the *same* line. And the ~ character works fine normally, so you should get used to using it.
As I said, the above code isn't compiling correctly. So I will add that to the bug list for the next version. But let's not get everyone confused by adding a lot of weird syntax to this. The $position=@{position} syntax isn't needed, and doesn't actually fix the problem.
As a temporary workaround, the fix is to change "stand" into "#SEND stand". So here is the corrected script for now:
Code: |
#if (@position != "Standing") {
$position = @position
#SEND stand
~chant %params
#execute %leftback($position,4)
} {
~chant %params
}
#print chant alias |
You could also replace your "~chant %params" with "#SEND chant %params". It's better to use the #SEND command when you want to send text to the MUD that you know isn't going to be some other alias. If "stand" needs to be an alias, then you can use "#EXEC stand"
Thanks for the link that wasn't working in the help files...I have fixed that now. |
|
|
|
charneus Wizard
Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Thu Apr 16, 2009 5:54 pm |
Whoops! My mistake about the @{position} bit, then.
I know I was thinking of something else where you HAD to use @{variable} but now I can't remember it for the life of me.
To be honest, though, he still has no need to use a local variable, I'd imagine, since the global is already defined and is being referenced here anyway. *shrug*
Sorry for the incorrect information, wrym. :P
Charneus |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Thu Apr 16, 2009 6:01 pm |
I have narrowed this down to the actual #LOCAL command. Here is the smallest script that shows the problem:
Code: |
#if (true) {
#LOCAL position
testing
} |
If the #IF statement is removed, then it works. If the #LOCAL command is removed, then it works. If the #LOCAL command is moved outside of the #IF statement, then it works. If the "testing" is replaced with a command like "#SEND testing", then it works.
So it only fails with a non-command statement following a #LOCAL command within an #IF block. Yeah, that's pretty obscure! But now that I have narrowed it down, it shouldn't be too hard to fix (crossing fingers). |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4691 Location: Pensacola, FL, USA
|
Posted: Thu Apr 16, 2009 6:49 pm |
charneus wrote: |
Whoops! My mistake about the @{position} bit, then.
I know I was thinking of something else where you HAD to use @{variable} but now I can't remember it for the life of me. |
This is mostly when dealing with DBvariables for something like @{this.$that} |
|
_________________ Discord: Shalimarwildcat |
|
|
|
wrym Magician
Joined: 06 Jul 2007 Posts: 349 Location: The big palace, My own lil world
|
Posted: Thu Apr 16, 2009 6:51 pm |
Whoho, I'm not crazy, and WEEE! more obscure bug fixes!
Thanks for the help. |
|
_________________ "To the engineer, all matter in the universe can be placed into one of two categories: (1) things that need to be fixed, and (2) things that will need to be fixed after you've had a few minutes to play with them" - Scott Adams, The Dilbert Principle |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Thu Apr 16, 2009 8:03 pm |
Wow, this one was really obscure and hard to find.
Turns out there were TWO bugs with this. The first bug was with the #LOCAL command as I indicated above. The command wasn't getting closed in the parser, so when it got to the next line, it still thought it was parsing local variable names.
However, after I fixed this I was still having trouble with the ~chant stuff. Turns out that when sending text to the MUD without the #SEND command (as when just saying "stand" on a line by itself), it also wasn't resetting one of the internal variables. So it considered the next line a continuation if it didn't start with a command or text. The ~ was messing this up. And rather than kludging it, I found the place were the end-of-line wasn't resetting the "send text" state and fixed that.
So now it all works. These obscure errors could definitely be causing some weird problems in scripts that send commands to the MUD without the #SEND command, so I'm glad we got it tracked down.
Just goes to show that when you have something that just doesn't seem to be working correctly, rather than look for weird workarounds, like putting \ in front of the text instead of ~ you should definitely report it to make sure it's not another strange bug.
Anyway, WOOT it's fixed now. Not what I was planning to work on today, but I'm glad I did. |
|
|
|
|
|
|
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
|
|