Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

multiplication and division using variables

i tried to increase the amount of gold by declaring a variable(gold) for it and then multiplied that control variable(gold) with 20.but the amount of gold remained unchanged.the problem with eventing is that it cannot be customized always.

in programming,what we do is-
declare variables 'i','j' and 'k'.then set
i=10
j=20
and then get the product by-
k=i*j

unfortunately i cannot declare a variable similar to 'k' in RMVX which would hold the value of the end product.how do i do it using events?i can assign values to i and j but cannot assign the result to 'k' using events.plz help me.
 
In Ruby, you don't have to declare variables. I believe your problem is actually scope. You are making local variables i, j & k. Outside a method they cannot be accessed (giving undefined method or local variable error). You could try game variables and increasing gold by them.

Or just clearify exactly what you are doing.
 
here is what i want to do exactly-

i want to introduce a currency exchange counter in the game.for that the two currencies which i would require to convert to and from is copper and gold.

the value of 1 gold=20 coins of copper.

when a currency would be converted,it would convert the entire amount of gold the party has.for example if the party has 100 gold,then by converting the currency to copper would change the actual value shown in the "gold" section to 2000 copper.(1 gold=20 copper,so multiply 100 with 20 to get equivalent amount of copper).its just like our foreign exchange counters where we exchange currencies when we want to visit a foreign land.

so now my problem is,i could change the value of gold to equivalent amount of copper by putting the 'change gold' option 20 times.but when i want to revert back the 2000 copper to its equivalent amount of gold(100 gold),then i cant implement the logic.i'm declaring a variable which is equal to the current amount of gold and then dividing the variable by 20.but that is not changing the amount of gold.

i realize the flaw in this logic-that after conversion i didnt mention any change of gold in the event.but the change gold option allows me to simply add or subtract amounts,not multiply or divide.so i'm stuck.
 
Control Variables: [0001] = Gold
Control Variables: [0001] *= 19
Control Variables: [0001] /=20
Change Gold: - Variable [0001]
Script: $data_system.terms.gold = "Gold"

Although you will inherently lose any remainder from the division. So if you're going to do this often, I would look at a different way.
For example, always store the value in copper, just in certain situations display it in gold.

Be Well
 
thanks,will get back as soon as i try it out successfully.but the script code scares the hell out of me. :sad:

i will just use this currency conversion once and that also when the characters visit a particular place.and when they leave the place they need to revert back to the previous currency(gold) as the other places will not accept copper.
 
Control Variables: [0001] *= 19.0
Control Variables: [0001] /=20.0

Yay at remainder OR

Control Variables: [0001] *= 19.0
Control Variables [0002] += [0001] % 20
Control Variables: [0001] /=20

Control Variables [0001] += [0002] / 20
Control Variables [0002] %= 20

THen you have the remainder in the second var, plus it auto adds any multiplication of 20 if needed in the last two lines.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top