Problem with simple division? (solved)

myke66myke66 Member Posts: 74
edited October 2013 in Working with GS (Mac)
Im trying to setup a variable that will store the percentage of progress from one number reaching another. For example:

Set attribute game.variableA to variableB / VariableC

so if its 50/100, the result should be .5, therefore 50% progress.

However, All I get is NaN. At first I thought it was because my number was too large, but im getting it when I put something simple in like 10/5. I couldnt find any syntax for how to divide...am I doing something wrong?

VariableA/VariableB <- Am i misssing any quotes or dots or anything?

EDIT:

It was a stupid mistake as I thought, the result was returning decimals and the variable was set to integer. Must be Real.

Comments

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited October 2013

    Hi @myke66

    Bit confused what you're after: because if I understand you correctly, you've already got the percentage right there, immediately...

    In other words, if your starting figure is 100 as your 100%, taking integers from it will be the amount left as a percentage.

    So using a Change Attribute PercentVar to PercentVar - NumberVar will change the attribute PercentVar to the percentage you want, for instance....

    Any help, or have I misunderstood something?

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • myke66myke66 Member Posts: 74
    I very much appreciate the reply gyroscope. My problem happened from my attribute being an integer instead of a Real number to get the decimals, thats why I kept coming up with 0.

    This was my attempt at making an updating exp bar. Here's how I did it..

    varExpToNexlLevel
    varExpCurrent
    varExpBarWidth

    I have Expbar.width constrained to varExpBarWidth. ExpBarWidth gets its value from varExpCurrent / varExpToNextLevel * 110 (the bar width). This way, it will always resize the bar based on the % to next level.

    The problem I was having was getting the percent, but like i said it was because the variable was an integer instead of a real number, nooby mistake!

    Hope this might help anyone.
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598

    Ah, OK, I understand what you mean now; glad you got it sorted too. :-)

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

Sign In or Register to comment.