Script error in commom event (about state)

Hello, there was a problem at the common event this time.



I thought that the state given is different depending on the hp situation of the actor.


So I made this code.

[#spoiler]

actor = $game_actors[14]




actor.add_state(142) if (($game_actors[$game_variables[18]].hp/$game_actors
[$game_variable[18]].mhp))*100 >= 20





actor.add_state(143) if (($game_actors[$game_variables[18]].hp/$game_actors
[$game_variables[18]].mhp))*100 <= 20

[#/spoiler]

For variable number 18, the script was used to store the id of the actor targeted by the skill.


So I built and start it, but


The error game_actor can't be coerced by fixnum occurred.


So I subtracted game_variable[18] and tried to put the number (id of the actor to be skill target), but the same error occurred.

Why is it like this?
This is/was a common issue with script commands where your window size is limited:
If you break up a line in Ruby, make sure that the lines cannot be interpreted as separate statements, since line breaks are also used as a separator. Alternatively you can end a line with a backslash to indicate that the statement should be continued in the next line.

So instead of
$game_actors
[14]


you can use
$game_actors[
14]

or
$game_actors\
[14]
This is/was a common issue with script commands where your window size is limited:
If you break up a line in Ruby, make sure that the lines cannot be interpreted as separate statements, since line breaks are also used as a separator. Alternatively you can end a line with a backslash to indicate that the statement should be continued in the next line.

So instead of
$game_actors
[14]


you can use
$game_actors[
14]

or
$game_actors\
[14]


As you said, I modified it like this.


1660619499747.png


But when I ran it, I got this error.

1660619797715.png


In this case, is there a problem with my code?
The code seems fine. Try to break the line after the division (end the line with .hp/ and put what follows on the next line).
You have an extra opening square bracket on your first line. Also typo on game_variable (missing an 's'). Second line has typos too.

And it looks like you'll run into integer division problems. Do this instead
Code:
actor.add_state(142) if ($game_actors[$game_variables[18]].hp * 100 / $game_actors[
$game_variables[18]].mhp)) >= 20
Adjusting for correct line breaks as previously called out in the thread.
You have an extra opening square bracket on your first line. Also typo on game_variable (missing an 's'). Second line has typos too.

And it looks like you'll run into integer division problems. Do this instead
Code:
actor.add_state(142) if ($game_actors[$game_variables[18]].hp * 100 / $game_actors[
$game_variables[18]].mhp)) >= 20
Adjusting for correct line breaks as previously called out in the thread.
Thank you, everyone.

So I modified it like this.

1660711461305.png



But this time, another problem has arisen.


It seemed to work normally if you put a number in the first line, but as shown in the picture above, the following error occurred when you put and run the variable.

1660711422956.png




In case the script didn't work, I thought the variable was not given the actor's number, so I checked it in the battle test using the Matton \v[18], but the variable was normally assigned the actor's number.



Here's how I've worked so far.


1. Insert the corresponding common event into Skill 1 and run it immediately.

But when it didn't work, I tried the following way.



2. First, put the function of storing the number of the actor in the variable in Skill 1. Using other scripts, change Skill 1 to 2.

After that, I put a common event in Skill No. 2 and designated the same actor as the target No. 1, but the following error occurred.


Why is it like this?
Thank you, everyone.

So I modified it like this.

View attachment 238030


But this time, another problem has arisen.


It seemed to work normally if you put a number in the first line, but as shown in the picture above, the following error occurred when you put and run the variable.

View attachment 238029



In case the script didn't work, I thought the variable was not given the actor's number, so I checked it in the battle test using the Matton \v[18], but the variable was normally assigned the actor's number.



Here's how I've worked so far.


1. Insert the corresponding common event into Skill 1 and run it immediately.

But when it didn't work, I tried the following way.



2. First, put the function of storing the number of the actor in the variable in Skill 1. Using other scripts, change Skill 1 to 2.

After that, I put a common event in Skill No. 2 and designated the same actor as the target No. 1, but the following error occurred.


Why is it like this?
The error message is telling you exactly what the problem is. game_variables isn't a thing. It's supposed to be $game_variables. For some reason, you're typing it inconsistently--half the time you're doing it right, and half the time you're doing it wrong.
You should be using the actor variable instead of the $game_actors whatchamecallit starting at line 2.
The error message is telling you exactly what the problem is. game_variables isn't a thing. It's supposed to be $game_variables. For some reason, you're typing it inconsistently--half the time you're doing it right, and half the time you're doing it wrong.
Thank you. I think I finally got what I wanted!

Original thread: https://forums.rpgmakerweb.com/threads/script-error-in-commom-event-about-state.150487/