GameMaker Help

B

Bill_blorngus

Guest
(This a repost after I realized I put it in the wrong place)

Hi, I made an account just for this. I am taking a programming and game design class at my local college, I have a problem with a script that the teacher wrote for the tutorial series of "space rocks" which he is having us follow. Where the tutorial has you write the first script, the teacher said that it doesn't work anymore due to a recent update. He posted his own script instead, and, using it in place of the original one, it came up with two errors. The first was involving global.cameraY, which the teacher got back to me on, and helped me fix. When I fixed it, another error came up after going from the starting title screen to the actual game. The teacher hasn't gotten back to me in three days, and this was due last Sunday (the 20th). I will post both the errors and the custom script below, I just need to know what to do and how.
The newest error:
############################################################################################
ERROR in
action number 1
of Other Event: Room Start
for object Obj_game:

global variable name 'cameraHeight' index (100011) not set before reading it.
at gml_Script_spawn_off_camera (line 31) - global.cameraY + global.cameraHeight + pad
############################################################################################
gml_Script_spawn_off_camera (line 31)
gml_Object_Obj_game_Other_4 (line 3) - spawn_off_camera(Obj_ast, 40)

The custom script after the first fix
function spawn_off_camera(_object, _number){

var xx,yy;

var pad = 64;

global.cameraY = 15 (this is the fix for the other one)


repeat(_number){

xx = random_range(0,room_width);

yy = random_range(0,room_height);

while(point_in_rectangle(

xx, yy, global.cameraX - pad, global.cameraY - pad,

global.cameraX + global.cameraWidth + pad,

global.cameraY + global.cameraHeight + pad

)

){

xx = random_range(0,room_width);

yy = random_range(0,room_height);

}

instance_create_layer(xx, yy, "Instances", _object);

}

}
 

angelwire

Member
According to the error, global.cameraHeight has not been initialized. Look through the code to see where "global.cameraWidth" and "global.cameraX" are set. There may be a typo where "global.cameraHeight" is actually "global.camera_height" or "global.cameraheight" (neither of which would work). It could also be empty and you'll need a line of code somewhere that sets the value of "global.cameraHeight".
 
B

Bill_blorngus

Guest
According to the error, global.cameraHeight has not been initialized. Look through the code to see where "global.cameraWidth" and "global.cameraX" are set. There may be a typo where "global.cameraHeight" is actually "global.camera_height" or "global.cameraheight" (neither of which would work). It could also be empty and you'll need a line of code somewhere that sets the value of "global.cameraHeight".
there doesn't seem to be any typos, any idea what I should set global.cameraHeight to?
 

angelwire

Member
Did you find out where the values are set? If so can you post the values and tell me the object, event, or script they were it?
 
B

Bill_blorngus

Guest
Did you find out where the values are set? If so can you post the values and tell me the object, event, or script they were it?
This script was the first time those were posted, there doesn't seem to have any values for either. Tbh I'm not sure what this teacher wanted me to do with this when there are no values.
 

angelwire

Member
You'll definitely need to talk to your teacher to figure things out.
But a quick fix would be to add these 3 lines beneath "global.cameraY = 15":
GML:
global.cameraX = 15;
global.cameraWidth = room_width;
global.cameraHeight = room_height;
If that doesn't work, you can go into the room properties and find the camera and view properties and manually put those values into the code.
 

TheouAegis

Member
The script is trying to read a variable which has not been set yet. When you declare a variable as global, the game will create it automatically to an extent, but it will be undefined. You cannot read a variable until it has been defined which means writing at least one value to it. Somewhere in your project before you ever can run that offending line (or lines like it), you must give global.cameraHeight a value. typically, although not always, this is done in an object's create event.
 
B

Bill_blorngus

Guest
You'll definitely need to talk to your teacher to figure things out.
But a quick fix would be to add these 3 lines beneath "global.cameraY = 15":
GML:
global.cameraX = 15;
global.cameraWidth = room_width;
global.cameraHeight = room_height;
If that doesn't work, you can go into the room properties and find the camera and view properties and manually put those values into the code.
so I did that, and now it just opens up and freezes, and I have to use task manager to shut it down. I also deleted the things that they said to in the video.
 

angelwire

Member
On the line: while(point_in_rectangle... try adding a ! in front of "point_in_rectangle" so it looks like this: while(!point_in_rectangle.
That way you're asking if the point is not in the rectangle instead of if it is.
 
Top