• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Defined Arguments coming through as UNDEFINED

S

sir_derp

Guest
So I have a script, called "scr_create_room" which takes 5 inputs: an array and four numbers, but for some reason, the arguments are coming through as UNDEFINED, despite the fact that I did define them. Does anyone know why this might be?

I have provided an image and an alternate link.debugging_circled.png

Alternate Link to Image: https://s17.postimg.org/jlok1nflb/debugging_circled.png
 

jo-thijs

Member
Hi and welcome to the GMC!

The image you posted is a bit misleading, as you can tell by reading the stack trace in the error message,
that the error is thrown later than the point you marked in your code.

There are 2 kinds of undefined in GameMaker:
undefined because you've never assigned a variable a value
and undefined because a function had nothing to return, even though something was expected
(like ds_map_find_value when a key is provided the map doesn't contain, or ds_list_find_value, when an unvalid index is given).

In your case, I think you're dealing with the second kind of undefined
and I'm thinking either x1, w or i gets set to it somehow.

Could you provide more code, so we get a total image of the codes the error message is talking about?
 

Weird Dragon

Wizard
GMC Elder
@sir_derp

I don't understand why you are using the script_execute function.
You can just use the script names as functions.

Well, in most parts of your code it doesn't really matter, but at one place it does!

You have this line:
Code:
if (script_execute(scr_check_room_location, argument0, x1,y1,w,h) == false)
but according to the manual the script_execute function doesn't return anything so you can not check whether it returns false. The manual says N/A ( = not applicable).

So I guess that the script "scr_check_room_location" can return true or false; thus you could simply remove the script_execute function and type:
Code:
if scr_check_room_location(argument0, x1,y1,w,h) == false
***
Well, I don't know whether the value returned by the script would in fact be returned when you execute it with the execute_script function. Personally I wouldn't rely on that based on what the manual says regarding the script_execute function.
 
Last edited:

jo-thijs

Member
@Weird Dragon, I just tested it and script_execute does return whatever the executed script returns.
I've also got some old scripts that relied on that behaviour.
However, looking at the documentation, it isn't mentioned there.
 
S

sir_derp

Guest
Hi and welcome to the GMC!

The image you posted is a bit misleading, as you can tell by reading the stack trace in the error message,
that the error is thrown later than the point you marked in your code.
I am aware that the error in the stack message is from a different part, specificaly it's from the check_room_location script inside the create_room script. The reason it's undefined in that script is because it's being passed an undefined value from the create_room script. If you look at the global x2 variable, which was set within the create_room script, it turned out to be undefined.
But I'll provide an image anyway.check_room.PNG
 
W

wantafanta

Guest
I've had issues where "i++" has caused the same error in the latest version of Gamemaker, when i switched the code to "i+=1" it was fine.

Try changing that and see if the error remains.
 
S

sir_derp

Guest
I've had issues where "i++" has caused the same error in the latest version of Gamemaker, when i switched the code to "i+=1" it was fine.

Try changing that and see if the error remains.
The error is that x1,y1,h, and w are undefined inside the room_create and check_room_location scripts, and the error occurs before the script even gets to i++. I tried your idea anyway, but it didn't work.
 
M

MarcC

Guest
If i am wrong here i blame late night posting before bed.

Seems to me given the limited access to the code, that x2 being undefined is irrelevant to the issue, since nowhere is it being called.

The only variable we cannot see being defined based on the evidence provided is argument0 (room_array)

edit: i meant to say... we don't see the validation of the room_array value
 
S

sir_derp

Guest
If i am wrong here i blame late night posting before bed.

Seems to me given the limited access to the code, that x2 being undefined is irrelevant to the issue, since nowhere is it being called.

The only variable we cannot see being defined based on the evidence provided is argument0 (room_array)

edit: i meant to say... we don't see the validation of the room_array value
1) x2 is set equal to x1 in the room_create script, I did this so I could actually see the value of x1.
2) The room_array is not the variable giving the error, so it shouldnt be an issue.
 

FrostyCat

Redemption Seeker
Since the argument passing system has been changed in 1.4.1760 to allow infinite arguments, let's try this: Stop using script_execute() and just call your scripts like this:
Code:
room_array = scr_create_room(room_array, x1, y1, w, h);
If the changed code works, I'd call it a bug. In any case, you should not run scripts with script_execute() when their exact identities are known at compile time.
 
W

wantafanta

Guest
I copied your code almost word for word and wasn't able to recreate the issue, so I think the issue may be somewhere else.

I think you have to provide the whole code for each of the scripts, the area of the code you've provided in the screenshots doesn't seem to be adequate.
 

jo-thijs

Member
@sir_derp, we still don't have scr_build_level, scr_initialize_array or the rest of the keyboard enter press event (up to line 32).
Also, you do realize the variables you're showing in the debug window are global variables, while the error message isn't talking about global variables, right?
 
S

sir_derp

Guest
@sir_derp, we still don't have scr_build_level, scr_initialize_array or the rest of the keyboard enter press event (up to line 32).
Also, you do realize the variables you're showing in the debug window are global variables, while the error message isn't talking about global variables, right?
Yes, I am aware of how debugging works. The variable x2 is a global variable set equal to argument1 of the create_room script, and it is set before the check_room_location script is called. From this we can deduce the following:
-argument1 of create_room is UNDEFINED within create_room.
--Therefore: an UNDEFINED variable is being sent to check_room_location.
--- Therefore: the error in question is not located in check_room_location, because we know that it exists prior to said script being called.

The global variable x2 exists solely to aid in debugging by allowing us to deduce the preceding points. It is not part of the program logic itself, nor is it meant to be, it is meant to tell use that the error already exists by the time check_room_location is run and thus eliminate check_room_location as the source of the problem.
X2 is UNDEFINED because argument1 of create_room is UNDEFINED.


EDIT:
Here is an image that should make the error a bit clearer.debug_2.PNG
 
Last edited by a moderator:

jo-thijs

Member
Oh, I know what's causing trouble.
I missed that part in the first screenshot.
Weird Dragon was almost right on top of it.

You mixed script_execute(script_name, arguments, ...) and script_name(arguments, ...) up to an extent that confused yourself.

Again, the screenshot you posted this time is again misleading as it again doesn't show the place the error is thrown.
The error starts by this line:
Code:
script_execute(scr_generate_block(argument0[i, j], new_x + scale * i, new_y + scale * j));
in scr_build_level.

You probably meant to use either:
Code:
scr_generate_block(argument0[i, j], new_x + scale * i, new_y + scale * j);
or:
Code:
script_execute(scr_generate_block, argument0[i, j], new_x + scale * i, new_y + scale * j);
However, by mixing those up, you correctly execute scr_generate_block, but then you take its result (which is 0 by default)
as only argument for the script_execute, executing the first script in your asset tree, which happens to be scr_create_room.
However, as you don't pass any other arguments to script_execute, the arguments for scr_create_room are set to undefined, resulting in your error message.

The solution?
Follow the advice of Weird Dragon and FrostyCat.
 
S

sir_derp

Guest
Oh, I know what's causing trouble.
I missed that part in the first screenshot.
Weird Dragon was almost right on top of it.

You mixed script_execute(script_name, arguments, ...) and script_name(arguments, ...) up to an extent that confused yourself.

Again, the screenshot you posted this time is again misleading as it again doesn't show the place the error is thrown.
The error starts by this line:
Code:
script_execute(scr_generate_block(argument0[i, j], new_x + scale * i, new_y + scale * j));
in scr_build_level.

You probably meant to use either:
Code:
scr_generate_block(argument0[i, j], new_x + scale * i, new_y + scale * j);
or:
Code:
script_execute(scr_generate_block, argument0[i, j], new_x + scale * i, new_y + scale * j);
However, by mixing those up, you correctly execute scr_generate_block, but then you take its result (which is 0 by default)
as only argument for the script_execute, executing the first script in your asset tree, which happens to be scr_create_room.
However, as you don't pass any other arguments to script_execute, the arguments for scr_create_room are set to undefined, resulting in your error message.

The solution?
Follow the advice of Weird Dragon and FrostyCat.
Then why does the error message say that the error is at line 17 of scr_create_room, when that script is run before scr_build_level or scr_generate_block?

EDIT:
Strangely, commenting out scr_build_level removed the error, but I need that function to run so that doesn't actually fix anything.
 
Last edited by a moderator:

jo-thijs

Member
Because this line executes scr_create_room as well:
Code:
script_execute(scr_generate_block(argument0[i, j], new_x + scale * i, new_y + scale * j));
I know commenting out that line removes the error and I know you need that line for your project to work, that's why I suggested you change that line to:
Code:
scr_generate_block(argument0[i, j], new_x + scale * i, new_y + scale * j);
 
S

sir_derp

Guest
Because this line executes scr_create_room as well:
Code:
script_execute(scr_generate_block(argument0[i, j], new_x + scale * i, new_y + scale * j));
I know commenting out that line removes the error and I know you need that line for your project to work, that's why I suggested you change that line to:
Code:
scr_generate_block(argument0[i, j], new_x + scale * i, new_y + scale * j);
I tried it, and it worked, but why did it work? Can you explain why scr_generate_block was running a script without being told to?
 

jo-thijs

Member
You're executing the script scr_generate_block, which returns nothing right?
Well, since it returns nothing, GameMaker defaults its result to 0.
Your line then continues to execute this:
Code:
script_execute(0);
0 refers to the first script you've got in your project, which just happens to be scr_create_room.
 
Top