MV Using Input.isTriggered with variables

Hi everyone, maybe someone can help me.

I am working on a QTE System where a picture is shown with an arrow key displayed. Then you have to press the matching button (up, down, right, left). This I can make work with conditional branches and Input.isTriggered.

But since I want it to use it regularly but with different sequences I thought about using Input.isTriggered with a game variable. This way I just need to set the variables at the beginning of the event and won't need to change every line in the conditional branches.

Screenshot 2024-05-29 232301.png


This is what I've got so far. I'm sure I made a mistake in how I wrote the Input.isTriggered($game.Variables.value(1)), but since I'm relatively new to coding I just don't know what to change to make it work. Maybe someone can help me 🙂
I'm sure I made a mistake in how I wrote the Input.isTriggered($game.Variables.value(1))
👋 Try this instead:
JavaScript:
Input.isTriggered($gameVariables.value(1))
👋 Try this instead:
JavaScript:
Input.isTriggered($gameVariables.value(1))

Unfortunately it still doesn't work, but thanks for the idea 🙂
Have you also removed the . (dot) between "$game" and "Variables"?
It also doesn't help that the $game.Variables.value(1) part was inside quotes, so even if you did write that correctly you weren't passing the word "up" to Input.isTriggered, but "$game.Variables.value(1)".

Please try copy-pasting caethyril's answer again instead of your current input in the script.
Have you also removed the . (dot) between "$game" and "Variables"?
Yeah, I copied the code, so it is exactly what caethyril wrote.

Maybe it has to do with the ' symbols?

Because you have to write
Input.isTriggered('up')

But the stored variable if I check it in text only shows up without the '

But I really don't know how to change this, because it I set the variable to ''up'' the value is 0.

It also doesn't help that the $game.Variables.value(1) part was inside quotes, so even if you did write that correctly you weren't passing the word "up" to Input.isTriggered, but "$game.Variables.value(1)".

Please try copy-pasting caethyril's answer again instead of your current input in the script.
Like I said, I copied it and didn't wrote it by hand, to avoid missing something, but maybe I still made a mistake.

I can't check it know, but I will check it later and post another picture. This makes it easier for you to see my mistakes 🙂
In programming, you type '' only when there's a real string, but not when you are using a variable.

Example
Code:
Input.isTriggered('up')
but
Code:
Input.isTriggered($gameVariables.value(1))
"up", 'up', and `up` are all valid JS syntax for the 2-character string up. $gameVariables.setValue(1,'up') correctly assigns the string up to game variable 1.

The way you inspect the variable's value will affect whether you see quote marks, e.g.
  • Show Text: \V[1] = up.
  • In-game debug menu (F9 on the map during playtest) = up.
  • Console or Script command: console.log($gameVariables.value(1)) = up.
  • Console: $gameVariables.value(1) = "up".
(The console is a tab in the dev tools window; you can open that window by pressing F8 or F12 during playtest. Type/paste some code there and press Enter to get the result.)


I just tried this and it worked for me:

◆Control Variables:#0006 Text = "up" ◆Text:None, Window, Bottom : :Press the \v[6] button! ◆Loop ◆If:Script:Input.isTriggered($gameVariables.value(6)) ◆Text:None, Window, Bottom : :\v[6] was pressed! ◆Break Loop ◆ :Else ◆Wait:1 frame ◆ :End ◆ :Repeat Above
If it's not working for you, then check for any Parallel events (including common events) that set variable ID 1. (Tools -> Event Searcher can be helpful for this, but it won't find $gameVariables.setValue script calls.) A Parallel event could change the value of your variable before Show Text gets a chance to draw it.

Screenshots may help. If you're using plugins, you may also want to test with all plugins turned off (save your project to apply Plugin Manager changes before testing).
"up", 'up', and `up` are all valid JS syntax for the 2-character string up. $gameVariables.setValue(1,'up') correctly assigns the string up to game variable 1.

The way you inspect the variable's value will affect whether you see quote marks, e.g.
  • Show Text: \V[1] = up.
  • In-game debug menu (F9 on the map during playtest) = up.
  • Console or Script command: console.log($gameVariables.value(1)) = up.
  • Console: $gameVariables.value(1) = "up".
(The console is a tab in the dev tools window; you can open that window by pressing F8 or F12 during playtest. Type/paste some code there and press Enter to get the result.)


I just tried this and it worked for me:

◆Control Variables:#0006 Text = "up"
◆Text:None, Window, Bottom
: :Press the \v[6] button!
◆Loop
◆If:Script:Input.isTriggered($gameVariables.value(6))
◆Text:None, Window, Bottom
: :\v[6] was pressed!
◆Break Loop
◆
:Else
◆Wait:1 frame
◆
:End
◆
:Repeat Above

If it's not working for you, then check for any Parallel events (including common events) that set variable ID 1. (Tools -> Event Searcher can be helpful for this, but it won't find $gameVariables.setValue script calls.) A Parallel event could change the value of your variable before Show Text gets a chance to draw it.

Screenshots may help. If you're using plugins, you may also want to test with all plugins turned off (save your project to apply Plugin Manager changes before testing).

Thank you so much for your explanations and help.

I was so frustrated, I just tried it in a blank new game file and it works perfectly! Tbh I don't really know where the problem was, turning off all plugins didn't work and no other event used the variable.

To be sure I will just use the new project and will check if everything is working as soon as I add new plugins :3
Good luck! 👋
Closed as solved.

Original thread: https://forums.rpgmakerweb.com/threads/using-input-istriggered-with-variables.169103/