Error occurs in this script

When running a script in RPG Maker XP, I'm getting a NoMethodError with the message 'undefined method =nil:NilClass'. Where could this error be occurring and how can I resolve it?

I was gonna try to add some vore in this game but it seems like it just gives me an error and won't work.

# Define variables
$game_variables[1] = false # isShrunk
$game_variables[2] = false # isDrank
$game_variables[3] = false # isInMouth
$game_variables[4] = false # isInStomach
$game_variables[5] = false # isDigested
$game_variables[6] = false # isPoop

# Shrink the protagonist
def shrink()
$game_variables[1] = true
end

# Place the protagonist in a cup of juice
def place_in_cup()
$game_variables[2] = true
end

# Protagonist is in the mouth
def in_mouth()
$game_variables[3] = true
end

# Protagonist is in the stomach
def in_stomach()
$game_variables[4] = true
end

# Protagonist is being digested
def being_digested()
$game_variables[5] = true
end

# Protagonist comes out as poop
def comes_out_as_poop()
$game_variables[6] = true
end

# Main program
shrink()
place_in_cup()
in_mouth()

# Little girl drinks protagonist
for i in 1..5000
if i == 5000
in_stomach()
being_digested()

# Protagonist comes out as poop after 2 days
for j in 1..(48*60*60)
if j == (48*60*60)
comes_out_as_poop()
end
end
end
end
What in the name of tapdancing hell did I just read
I know that can sound weird and ed, but still, what could there be for an error?
What in the name of tapdancing hell did I just read
Where have you written this? What line does it say is erroring in the message?
Where have you written this? What line does it say is erroring in the message?
I did add it to the scripts label in RPG Maker XP and the line says Script Shrinking Scneario Code line 2: NoMethodError occured. undefined method =nil:NilClass
Can you show me a screenshot of the actual script editor?
Sure, here is this:
b6ed857b751ed62f1260871078179a6b.png
742454b9644d086c2b8b0c5cc16aa49b.png
bf4ea4f2c8105ec8d8523999d40bb324.png
Can you show me a screenshot of the actual script editor?
Okay so your issue is that you're trying to define methods outside of a class. That isn't how they work. What is the method supposed to belong to?
It should belong to the protagonist what she/he is doing.
Okay so your issue is that you're trying to define methods outside of a class. That isn't how they work. What is the method supposed to belong to?
...that's not what I meant.

In Ruby, two things have methods: modules and classes. Your defined methods are contained within neither of those things, so of course you're going to get an error.
So what I should type in for a module or class?
...that's not what I meant.

In Ruby, two things have methods: modules and classes. Your defined methods are contained within neither of those things, so of course you're going to get an error.
Oh alright, so what I should type in for a module or class?
Oh alright, so what I should type in for a module or class?
If you don't know that, where did you get the idea to type the code you tried in the first place, if I may ask?
Should he not also be using game_switches and not game_variables since game_switches is supposed to be boolean.
Is game_variables defined at the point he is declaring them?
This is an info for the OP @medialife98 that hopefully helps clear things up:

A script in the script editor is different from a script in the event command.

A program needs a structure to have it understand what is where, and in the script editor the script writer is supposed to program in that structure in a way that the intended code fits to the rest of the engine structure.
THAT is what the others are referring to when they talk about methods and classes and so on, and they can't tell you directly what to do because there are dozens of classes which different purposes.
And most of the complex scripts need their parts scattered between different classes to function in the engine and its game loop correctly, that is NOT easily done without intense knowledge of what is where in the engine.

In the script command of the event interpreter, the event interpreter handles all that and in fact it would be a bad idea to define classes there because the event command is sandboxed as well.

What you have there is basically the assumption that you can use a script like scripts done in the event command and just place it inside the script editor with no or minimal changes, and that won't work because it will be missing the framework that lets the engine decide where it belongs and when it should be executed.

Original thread: https://forums.rpgmakerweb.com/threads/error-occurs-in-this-script.157002/