Windows Errors with no fix

B

Bill_blorngus

Guest
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);

}

}
 

Neptune

Member
I think this is what you want?

GML:
global.cameraY = 15;

repeat(_number)
{
    var pad = 64;
    var xx = random_range(0,room_width);
    var yy = random_range(0,room_height);

    if point_in_rectangle(xx, yy, global.cameraX - pad, global.cameraY - pad,global.cameraX + global.cameraWidth + pad,global.cameraY + global.cameraHeight + pad)
    {
        //create something in camera view?
        instance_create_layer(xx, yy, "Instances", _object);
    }
}
I dont know what you're doing, but the while loop seemed unnecessary...


Alternative (better?) option:

GML:
global.cameraY = 15;

repeat(_number)
{
    var pad = 64;
    var xx = random_range(global.cameraX - pad,global.cameraX + global.cameraWidth + pad);
    var yy = random_range(global.cameraY - pad,global.cameraY + global.cameraHeight + pad);

    instance_create_layer(xx, yy, "Instances", _object);
}
This will ensure each time something spawns in the camera view.
 
Last edited:
Top