Grid System with FriendlyCosmonaut [P8]

A

ASOBU

Guest
thank you open this thread. I m bothering to an error that object Crops_system's roomWidth and roomHeight in Room_start.

Allow me to use odd English.

Now I reference from FriendlyCosmonaut Part8. I don't have any idea to solve the error aleady.



GML:
oCrops_system
------------------------Roomstart
//[P8]17:20
if (room == rm_1 and ds_crops_instances == 0)
{
    ds_crops_instances = ds_grid_create([COLOR=rgb(226, 80, 65)]roomWidth[/COLOR] div cellSize, [COLOR=rgb(235, 107, 86)]roomHeight[/COLOR] div cellSize);
}





<oGame>
----------------------------------------RoomStart
//to set cell---[FC:P8]2:55
roomWidth  = room_width;
roomHeight = room_height;

if(spawnRoom == -1) exit;
oPlayer.x = spawnX;
oPlayer.y = spawnY;
oPlayer.facing = spawnPlayerFacing;

with(oPlayer)
{
    switch (facing)
    {
        case dir.left : y_frame = 1; break;
        case dir.right: y_frame = 0; break;
        case dir.up   : y_frame = 2; break;
        case dir.down : y_frame = 3; break;
        case -1:        x_frame = 0; break;

    }
}
-------------------------------Draw
//Debug
if (!debug){  exit; }
with(oCOLLISION)
{
draw_rectangle_color(bbox_left, bbox_top, bbox_right, bbox_bottom, c_yellow,c_yellow,c_yellow,c_yellow,true);
}
with(oPlayer)
{
draw_rectangle_color(bbox_left, bbox_top, bbox_right, bbox_bottom, c_yellow,c_yellow,c_yellow,c_yellow,true);
}


//[FC:P8]5:00
var xx = 0;
var cs = oCrops_system.cellSize;
draw_set_alpha(0.3);

//[FC:P8]
var repeating = roomWidth div cs;
repeat(repeating)
{
    draw_line_color(xx, 0, xx, roomHeight, c_yellow, c_yellow);
    xx += cs;
}

var yy = 0;
var repeating = roomHeight div cs;
repeat(repeating)
{
    draw_line_color(0, yy, roomWidth, yy, c_yellow, c_yellow);
    yy += cs;
}

draw_set_alpha(1);


I tried to change "roomWidth" and "roomHeight" to room_width and room_Height. But it did not work. And I had been looking for a solution from Youtube comments.

Could someone please help meo_O
 

Attachments

Nidoking

Member
You're setting the roomWidth and roomHeight variables in the oGame, which means that they're part of oGame. If you want them to remain in oGame, then you need to tell oCrops_system where to find them. You would probably do that by specifying oGame.roomWidth (for example). That tells oCrops_system to find the roomWidth variable inside oGame. Another option would be to make them global variables, which don't live in an instance. You would refer to them as global.roomWidth (for example) everywhere.

Here is some useful reading material.
 
A

ASOBU

Guest
You're setting the roomWidth and roomHeight variables in the oGame, which means that they're part of oGame. If you want them to remain in oGame, then you need to tell oCrops_system where to find them. You would probably do that by specifying oGame.roomWidth (for example). That tells oCrops_system to find the roomWidth variable inside oGame. Another option would be to make them global variables, which don't live in an instance. You would refer to them as global.roomWidth (for example) everywhere.

Here is some useful reading material.
Thank you for replying. I tried using code global.roomWidth, and oGame.roomWidth. But both showed up the same error. And I challenged to move the valuable from oGame to new Object. But it also was the same outcome..

I'm really appreciating your help and material which you told
 

Nidoking

Member
I tried using code global.roomWidth, and oGame.roomWidth. But both showed up the same error.
I just noticed that you're setting these variables in the Room Start event for both objects. That's not a good idea, because it creates a dependency in the order in which the two events run. Why don't you just use room_width and room_height directly? What is the purpose of creating more variables to hold the same information?
 
A

ASOBU

Guest
I just noticed that you're setting these variables in the Room Start event for both objects. That's not a good idea, because it creates a dependency in the order in which the two events run. Why don't you just use room_width and room_height directly? What is the purpose of creating more variables to hold the same information?
I completely imitated the tutorial of the Youtube video, and I guess she wanted to get room size at room started. and she would like to set valuables which are made for a certain event.
In addition, I tried to set room_width and room_height directly twice, but it did not run and gamemaker does not show an appropriate game debug window.
Sorry, If my sentences are confusing you. and I felt happy to accept a message from you again.
 

Nidoking

Member
In addition, I tried to set room_width and room_height directly twice, but it did not run and gamemaker does not show an appropriate game debug window.
You can't set room_width and room_height. They are read-only variables. What I'm asking is why you need a variable called roomWidth that holds the value of room_width. The variable room_width already holds the value of room_width. Why do you need to do this:

GML:
ds_crops_instances = ds_grid_create(roomWidth div cellSize, roomHeight div cellSize);
when you could do this:

GML:
ds_crops_instances = ds_grid_create(room_width div cellSize, room_height div cellSize);
If you can explain why there is a difference between the two and why you must use the first one, then there may be some value in pursuing a solution. If you can't, then the second part should work with no problems.
 
A

ASOBU

Guest
I just had done as you indicated here. But I think I don't really understand why I have to write a variable called roomWidth.
So I will try to check this variable one more.

Thank you for your kindness, I guess you would be busy because of the end of the year. Have a great year:)
 
Top