Non-threaded

Forums » Advanced Editor Forum » Read Thread

Get help from the experts on variables, scripts, items, and other scary things.

Is Maths Broken?

9 years ago
So I have this variable, SCORE. I have a second variable, SGDR. I need to display text based on the value of SGDR. That works fine. I need to calculate SGDR from the value of SCORE. I am using this code:

%SGDR := %SCORE / 10

When SCORE is between 0 and 69, this works great. SGDR receives values of 0 to 6, no problem. However, when SCORE is greater than 69, SGDR remains at 6 no matter what I do. Yes, I am really sure the code line above is executed. I am displaying both values on the screen and I get SCORE = 90 and SGDR = 6 (and so on). And yes, I'm executing that code on a different page, before the page displaying the variables is displayed. In fact, I do the exact same steps repeated times to increase SCORE using the same page -- increase to 20, SGDR increases to 20. Use the same page, increase to 50, SGDR is set to 5. Use the SAME page, increase to 75, SGDR is six.

Is there some strange limitation on division in the code? Is there some reason I can't divide by 10 and get a number greater than 6?

Is Maths Broken?

9 years ago

I think the problem might lie somewhere else. I just ran the following code:

%TEST := 50

%SCORE := %TEST / 10

$PAGETEXT := $PAGETEXT + "<p>" + %SCORE + "</p>"

%TEST := 60

%SCORE := %TEST / 10

$PAGETEXT := $PAGETEXT + "<p>" + %SCORE + "</p>"

%TEST := 70

%SCORE := %TEST / 10

$PAGETEXT := $PAGETEXT + "<p>" + %SCORE + "</p>"

...and got 5, 6, and 7 as output.

Is Maths Broken?

9 years ago
Thank you very much for testing that for me!

That helps me because it means I must be doing something else... somewhere... silly piles of code all over the place! I'll start searching other sections of code.

Thanks again!

Is Maths Broken?

9 years ago
What's your max value on SGDR?

I once had a weird error where because I set the max value to 1, it never went above 1. Pretty logical if you think about it, but I never thought the variable max would come into play in scripting.

Is Maths Broken?

9 years ago
Thanks for the tips -- yes, that was it. I was originally using SGDR for one thing, and I had set the max to 6. Now I was trying to do something else and splat, SIX!

Is Maths Broken?

9 years ago
No problem. Glad to see it was a simple fix.

Is Maths Broken?

9 years ago

Also check your script, to make sure you aren't changing %SGDR after the fact. In  other words, setting it to your value, then later in the script setting it to another value. (This variable change would not show on the page if it is happening in a Page Script on the same page).