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.

for my script

Nava

Member

ok im making a script and i want it to have a variable that i can change by clicking on an event in the game does anyone know how to do this??
 
To be exact, setup your event with a Script processing event command (should be close to the bottom of the last page) and insert the following:

Code:
$game_variables[id] += 1 # to add 1 to the variable
$game_variables[id] = 1 # to set the variable to 1
$game_variables[id] = $game_variables[id] # to set the variable equal to another variable

You need to change the id for every variable, though.
 

Nava

Member

yea but my variable is in the script not in the game do i have to put it in the game because my variable is something like $variable i think i called it
 
I don't really know what you are trying to do, but you can change it by using:
Code:
$variable = number
$variable += number
$variable -= number
$variable *= number
$variable /= number
$variable %= number

But you really shouldn't make it a global variable unless it has to be. You could just make a new instance variable in Game_Temp instead, or Game_System if you want it to be saved in save files.
 

Nava

Member

yea i need it so that when i talk to this person in an event the number of the variable is increased by one and it is permanent. likei think i stated b4. so if i do all of that when i talk to the guy every time he will increase the variable by onme and it will stay that way or wil it only in crease it to 1 each time?
 
Okay, for this it would be better to use a $game_variable. In the event, choose control variables(page 1, second column, second command, choose the variable you want to go up, then choose + for the operation. For the Operand, choose Constant and enter 1. Each time you talk to this event, the variable will go up by one.
 

Nava

Member

yea but the variable isnt in the game its in the script is there a way to change the value of the variable thats in the script with an event or do i have to make a def that will do all of that for me and then call it in the event?
 

Nava

Member

*Bump*

can some one please help. if i mademy variable in the script what syntax do i have to use to call and permanently add one to the variable each time the event is clicked because my variable wasnt created in the game so i need a code to put in the script and call to increase it for me does ne one kno how to do that???
 

Nava

Member

what syntax do i use to do that?? i want it to be that you have to hit the event so many times for it to work. so lets say i wanted it to be 15 for the variable but it starts at 0. now the program is going to to an equation its going to multiply that variable by 3. so at first it equals 0 which reults with a message saying that the number you have is incorrect. now to have it be right you have to hit the action key on the event, 5 times. how do i make it so that when i hit the event 5 times then walk over to clerk which is the evnt which calls the script, does the multiplication, and shows the output. how do i make the variable stay at 5? i kant figure it out. i just dont know the right syntax for it. if you dont understand this then i will try and explain again. but if you or anyone else know this i would be more than greatful because i really need this!!!! its the part that im stuck at on my script if i get this i willbe able to continue, so please i need some hel and thanx for your time!
 

Nava

Member

no they explained a syntax for the variable if it was in the game but i will try and use that but im not sure if it will work for what i am trying to do. thanx for your time
 

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