 |
Rivo Newbie
Joined: 11 Apr 2006 Posts: 9
|
Posted: Thu Sep 28, 2006 11:31 am
[1.07] Variables change their values after definition |
Actually this is a bug in all released Cmud betas. When I define a variable like:
abc=xxxxx or #var abc xxxxx
SOMETIMES the content of @abc is no longer xxxxx
If check this problem with the following command:
Quote: |
#loop 255 {#var abc %char(%i)
#if (@abc<>%char(%i)) {#show -%i-@abc-}} |
It could be found that three characters %char(178),%char(179) and %char(185) degrade into zero (%char(48) in fact) after saved in any variables.
I assume the problem is quite clear and could be fixed as a piece of cake by mighty Zugg . |
|
|
 |
Zugg MASTER

Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Thu Sep 28, 2006 4:01 pm |
This probably depends on the language setting in Windows. CMUD asks Windows to decide which characters in the language are numbers and letters. My guess is that %char(178),%char(179) and %char(185) are being flagged as numbers and then converted to zero somehow.
You might try first initializing @abc and then go to the settings editor and force the variable type to be a "string" intead of "autotype" and see if that helps. I'm away from my development system right now so can't really try it myself. |
|
|
 |
Rivo Newbie
Joined: 11 Apr 2006 Posts: 9
|
Posted: Thu Sep 28, 2006 5:01 pm |
Thanks for the reply, Zugg
I just switched my language setting from English(UK) to English(US) and it's still the case that values of the three characters (superscripts 1,2,3) change to 0 if evaluated (via either #var or %eval).
Forcing the variable type to "string (literal)" manually does solve this problem but only works once. Next time when "#var abc" is used the variable type of @abc will go back to "autotype". Set Default to "string (literal)" and tick "use default" won't help.
Is there any command able to specify the variable type after a variable is defined?
Cheers |
|
|
 |
Zugg MASTER

Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Thu Sep 28, 2006 6:51 pm |
Yes, there is a %vartype function. Here is the F1 help:
Code: |
Returns the current type of a variable.
0 = Auto, 1 = Integer, 2 = Expanded string, 3 = Literal string, 4 = String list, 5 = Database record, 6 = Array, 7 = Floating point, 8 = COM reference. |
It also sets the variable type. For example:
Code: |
#CALL %vartype(abc,3) |
Also, I looked into this and I don't see any reason to use the Windows settings for numeric characters. Seems like just using 0..9 for numbers is good enough. It's different with alphabetic characters when deciding what %w should match for a word, but for %d matching numbers, it seems that just forcing it to 0..9 would be fine. That would fix the problem with the superscript "numbers". |
|
|
 |
Seb Wizard
Joined: 14 Aug 2004 Posts: 1269
|
Posted: Thu Sep 28, 2006 6:52 pm |
There is a way to change the value of variable without using the #var command (even in zMUD). #var redefines (or deletes and recreates) the variable, and so it will lose the variable type. Instead, create the variable once, and then use:
to change the value of myvar to newvalue (notice the absence of the @). |
|
|
 |
shalimar GURU

Joined: 04 Aug 2002 Posts: 4755 Location: Pensacola, FL, USA
|
Posted: Thu Sep 28, 2006 7:28 pm |
i thought the
var=value
was just a shorthand method and essentially did use the #VAR syntax in the background |
|
_________________ Discord: Shalimarwildcat |
|
|
 |
Seb Wizard
Joined: 14 Aug 2004 Posts: 1269
|
Posted: Thu Sep 28, 2006 7:39 pm |
Well, how can it, since it can't contain all the parameters that #VAR has? I have to admit that is just an assumption I made - I haven't tested this on CMUD.
|
|
|
 |
Zugg MASTER

Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Fri Sep 29, 2006 1:23 am |
Actually, in CMUD the var=value and #VAR commands use the exact same code internally. The var=value syntax just uses the default values for the "default" and "class" arguments, so it's exactly the same as "#VAR var value". In zMUD they were handled by different sections of the parser, but the new parser in CMUD handles both cases.
|
|
|
 |
Zugg MASTER

Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Fri Sep 29, 2006 4:03 am |
Btw, this issue should be fixed in 1.08.
|
|
|
 |
edb6377 Magician

Joined: 29 Nov 2005 Posts: 482
|
Posted: Sat Sep 30, 2006 12:05 pm |
the other problem in zmud was doing myvar=bob could very well end up creating multiple copies of a variable. Especially behind class folders.
|
|
_________________ Confucious say "Bugs in Programs need Hammer" |
|
|
 |
Seb Wizard
Joined: 14 Aug 2004 Posts: 1269
|
Posted: Wed Oct 04, 2006 7:25 pm |
And what exactly does "#VAR var value" do if variable var is already defined? e.g. If var is already defined in Class1 with default def, and you use "#VAR var value", will var in Class1 be changed, even if the script that executed the command is in a different class? If there was a default already set on var will it now be removed? What happens if Class1 is disabled? Does a new var get created in the current class now? This is how I feel it works in both zMUD and CMUD from my experience and what Zugg said above, but there is nothing on this in the zMUD Help files.
|
|
|
 |
Zugg MASTER

Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Thu Oct 05, 2006 3:48 am |
Yes, if "var" already exists in any enabled class then that value will be changed. To force the value to be changed in the current class, you need to use the ./var syntax just like with local file references. If Class1 is disabled, then as far as CMUD is concerned, the variable doesn't exist (isn't visible) so it will get created in the default class.
Except for the ./var syntax being the opposite of the zMUD syntax (which uses /var instead), this is the same as it works in zMUD and won't be changed for compatibility. |
|
|
 |
|
|