• Hey! Guest! The 39th GMC Jam will take place between November 26th, 12:00 UTC and November 30th, 12:00 UTC. Why not join in! Click here to find out more!

GMS 2 (DnD) DoConv :1: illegal undefined/null use

jbutler27

Member
I'm pretty new to game design, and programming specifically, so I'm hoping these types of problems will make more sense to me as time goes on. As of today, all the scripting and "argument" and "target" stuff feels a little more familiar, but it all gets me jumbled up if something doesn't go perfectly smooth when I try to run it--I have no idea where to even look. I've been following a tutorial for this, too, which makes it even more frustrating that I can't get it right. Anyway, when I try to do a test run, I get this error message:

___________________________________________
############################################################################################
ERROR in
action number 1
of Create Event
for object <undefined>:

DoConv :1: illegal undefined/null use
at gml_GlobalScript_spawn_off_camera (line 19) - repeat(number)
############################################################################################
gml_GlobalScript_spawn_off_camera (line 19)


Because the problem seemed to stem from the "number" argument, I decided to change it to an actual, numerical variable, and see what happened (I tried 1000 at first, and then I tried 10). But this didn't help me at all, as the game just entered a stalled, hung-up state and no window even opened up. In the Output feed, after all the chunks and everything loaded, this is what it stopped on:

...
Writing Chunk... DFNC
Writing Chunk... STRG
Stats : GMA : Elapsed=1095.0059
Stats : GMA : sp=8,au=6,bk=0,pt=0,sc=1,sh=0,fo=1,tl=0,ob=7,ro=4,da=0,ex=0,ma=5,fm=0xB20829F80020
DoSteam
Igor complete.
[Run] Run game
Options: Z:/SpaceRocks_E8718113\MainOptions.json
X://windows/Runner.exe -game "Y:/SpaceRocks_975F412_VM\SpaceRocks.win"
Attempting to set gamepadcount to 12
DirectX11: Using hardware device
Collision Event time(microsecs)=3



Here's the code for the script:

// GameMaker Language Preview (Read-Only)

// Declare Temp
var obj = argument0;
var number = argument1;
var pad = 64;

// Repeat
repeat(number)
{
// Declare Temp
var boundCheck = true;

// While Loop
while ((boundCheck == true)) {
// Get Random Number
var xx = (random_range(0, room_width));

// Get Random Number
var yy = (random_range(0, room_height));

// Function Call
with(obj_camera) {
var boundCheck = point_in_rectangle(xx, yy, cameraX - pad, cameraY - pad, cameraX + cameraWidth + pad, cameraY + cameraHeight + pad);
}
}

// Create Instance
instance_create_layer(xx, yy, "Instances", obj);
}






...I don't even know where to begin. Any help at all would be appreciated!
 

TsukaYuriko

🌠
Forum Staff
Moderator
The message complains that you're using undefined when you shouldn't. The only variable that could be undefined - as in, the only variable on that line at all - is number. This will be undefined if you don't pass in any value for the second argument of the script.
 

rytan451

Member
I don't even know where to begin.
Since the window is complaining about something being undefined, check for variables that you're getting the value of (like number) but have not yet set.

As for freezing... are you sure that the camera (plus padding) isn't covering the entire room? Why not split the room into five rectangles (one rectangle is the camera, the other four cover the rest of the room without overlapping), figure out the area of the rectangles, choose one of the rectangles weighted by area, then choose a random point inside the rectangles? This is much less likely to result in an infinite loop (though more likely to cause bugs if you make a mistake — remember to consider the case where the dimensions of the rectangles are negative, or when all of the four border rectangles have no area!)
 

jbutler27

Member
Thank all of you for the replies -- but despite my efforts, I just cannot seem to understand how to format the script. I know what I need it to do, but I don't have a clue what I should do to make it function. Like, how does typing "boundary check" explain to the script what I'm trying to accomplish? I know I can feed variables/arguments into the equation, but I don't know how the program reads those variables or arguments. Feels like I need to read a book or something, but that's kind of what this tutorial was supposed to help with! But now I feel so fully out of my depth that I'm questioning my ability to do this.
 

FrostyCat

Member
The tutorial was written for a version before GMS 2.3, and GMS 2.3 has made a major shift in the way script functions are declared.

When you create a script in GMS 2.3 Drag-and-Drop, you should get a "Declare A New Function" action to start. This is where you will declare what the script function will be named (multiple of them can be in one script now), and what arguments the script function will accept (click the + to include more arguments). It is no longer the Declare Temp with argument0 and argument1.

This is how your setup should start:
1600730426127.png
 

jbutler27

Member
@FrostyCat Phenomenal help. That got the ball rolling for me, and in about 30 minutes or so I was able to put the script together and run it with "Execute Script." A sticking point for me came from some bad advice about how you no longer need to execute a script, but rather you're supposed to "call" the script as a function (I wasn't sure what to use as arguments at that point). So that confused me a bit, but you set me on the right track. Thank you very much. The script now works as intended.
 
Top