|
Dumas Enchanter
Joined: 11 Feb 2003 Posts: 511 Location: USA
|
Posted: Sat Jul 15, 2006 5:02 pm
Syntax Error |
setting editor is giving me a syntax error whith the following
Code: |
#VAR storage
#VAR number %1
#if (@number=0) {#ABORT 1}
#UNTIL (@number=0) {#if ((@number\2)=1) {%concat(1,@storage);#MATH number (@number/2)} {%concat(0,@storage);#MATH number (@number/2)} |
Basically, it is an alias that takes a number, and while the number is not 0 checks to see if the number variable is divisible by 2. If it isn't, it concatenates a 1 on the storage variable, and if it is, it concatenates a 0. Then stored number is replaced by the integer value of itself divided by two.
For example, using 118:
118/2 = 59 rem 0
59/2 = 29 rem 1
29/2 = 14 rem 1
14/2 = 7 rem 0
7/2 = 3 rem 1
3/2 = 1 rem 1
1/2 = 0 rem 1
storage should end up looking like 1110110 |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Sat Jul 15, 2006 7:42 pm |
based on the posted code, you seem to be missing the closing brace for the #UNTIL command.
|
|
_________________ EDIT: I didn't like my old signature |
|
|
|
Dumas Enchanter
Joined: 11 Feb 2003 Posts: 511 Location: USA
|
Posted: Sat Jul 15, 2006 8:31 pm |
Doh.
Though it seems that %concat doesn't work how I thought it did. How would I just concatenate onto an existing variable? |
|
|
|
Larkin Wizard
Joined: 25 Mar 2003 Posts: 1113 Location: USA
|
Posted: Sat Jul 15, 2006 9:44 pm |
1. I think you need a value for the first #VAR command (#VAR storage) for it to be useful.
2. For your %concat to work, you need to assign the value it returns to your variable (number = %concat(1, @storage), for example).
3. Using #ABORT can have strange side effects (easily explained, but often unexpected), so you may want to simplify your #IF to just: #IF (@number != 0) {#UNTIL blah blah}.
4. Your first division has a backslash instead of a forward slash.
5. MattLofton already mentioned the missing curly brace at the end. |
|
|
|
Dumas Enchanter
Joined: 11 Feb 2003 Posts: 511 Location: USA
|
Posted: Sat Jul 15, 2006 10:00 pm |
The @number\2 is done on purpose as zMUD does the division and returns the remainder only. To me, it is easier to check to see what the remainder is due to the division by 2, where you will only get a remainder of 0 or 1.
I'll try #1 and most definetly #2.
Edit: Okay, I switched from #VAR storage to just storage="" on the first line. Remembered I needed to clear the variable out each time so it wouldn't just keep cancating.
#2 is what did the trick. Thanks Larkin |
|
|
|
|
|