Else if conditional script help with variables.

Hi, I am new to javascript and RPG maker scripting (also the forum). Currently, I am trying to convert a dating sim I made in twine, into RPG maker MV but I am rather confused. Currently, this system is supposed to check the character's (you the player are interacting with) affection, then check the random "roll" variable which is updated every time the event is accessed, to then change how the character responds to the player. This is exactly how it works in my twine version of the game, I just have no clue how to convert it, I did try some standard javascript stuff but it didn't work either.

Real.PNG
Try putting all of that into a single script call, not 5 different calls.

I'm also not sure if $gameMessage.add is the only thing you need to do, to get a message to display via script. Because you just said "it didn't work" without saying what IS happening, I don't know if it's just that the wrong message is showing, or NO message is showing, or if you are getting an error. More information when something "doesn't work" is helpful.
just for information:
the script command is intended for small things, larger scripts should be done as plugins and called from there.
because of this the script command is basically sandboxed - any variables defined in one script box will be deleted once that script box is closed. You would need to define variables outside the script box to keep their values - either by plugin or by control variable event command.

you might want to look into using event commands anyway, because that is what they are defined for. And some features are better integrated by event command while other options are better done by script functions. But you'll need to know both to be able to see when the javascript and when the event command would be the better solution.
Try putting all of that into a single script call, not 5 different calls.

I'm also not sure if $gameMessage.add is the only thing you need to do, to get a message to display via script. Because you just said "it didn't work" without saying what IS happening, I don't know if it's just that the wrong message is showing, or NO message is showing, or if you are getting an error. More information when something "doesn't work" is helpful.
I apologize I was actually thinking I put too much information in. So I merged all the script calls, into one. Still no message displays, the only thing that happens is the event image flashes. I was able to get an $gamemessage.add to work by itself, but not within the if statement. (Yeah the $gameMessage.add only worked when I set up the background and position. )
I didn't know that Andar thank you both, I did figure out a rather barbaric way of doing it with events/ common events/ and such. I did not know that about scripts, and temp variables but I was going to define them outside of it.
You could ditch the $gameMessage.add commands, and just set a variable to whatever text you want, via $gameVariables.setValue(5, "Hi") in the script. Then in your Show Text event, put \v[5] to display what's in that variable.

But yeah, I'd personally just ditch the scripts altogether and use conditional branches and show text.
If you don't want to dedicate game variables to this, you can get around the block-scoped nature of the script command by using "window.whatever" as your identifiers, and they'll persist between script calls.
Thread closed

Original thread: https://forums.rpgmakerweb.com/threads/else-if-conditional-script-help-with-variables.141617/