RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
Variables giving me a problem... [resolved]

0 Members and 1 Guest are viewing this topic.

**
Rep: +0/-0Level 85
I want to be able to calculate and store a percent..  Since the default variables don't hold decimals and can only perform one mathematical operation at a time I figured I would try to use RGSS to perform my calculations and store the resulting percent back into one of the default variables..  This was the line I used to try and store the value:

$game_variables[17]=($game_variables[15]/$game_variables[16])*100

When I do this though I get the following error once the game reaches that line:

nil can't be forced into Fixnum

Anyone know what mistake I made?..

edit: added resolved tag
« Last Edit: September 24, 2008, 01:28:13 PM by NAMKCOR »

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
I take it you are trying to run that with the Event Script command.

It's too long - the interpreter interprets it in the wrong way for your purposes.

Try this:

Code: [Select]
a = $game_variables[15]
b = $game_variables[16]

$game_variables[17]=(a / b)*100

On the other hand, you could also avoid RGSS totally by just multiplying by 100 before dividing in the events like this:

@>Control Variables: [17] = Variable [15]
@>Control Variables: [17] *= 100
@>Control Variables: [17] /= Variable [16]

**
Rep: +0/-0Level 85
I take it you are trying to run that with the Event Script command.

It's too long - the interpreter interprets it in the wrong way for your purposes.

Try this:

Code: [Select]
a = $game_variables[15]
b = $game_variables[16]

$game_variables[17]=(a / b)*100

On the other hand, you could also avoid RGSS totally by just multiplying by 100 before dividing in the events like this:

@>Control Variables: [17] = Variable [15]
@>Control Variables: [17] *= 100
@>Control Variables: [17] /= Variable [16]

Ah yes, I don't know why I didn't think of that.  That helps a lot, thanks..