draw_text(xx + 4, yy + 4, string(ds_list_size(neighbors)))

K

kingvamez

Guest
when ever i enter this code for a grid system in a game this error message appears

___________________________________________

############################################################################################

FATAL ERROR in

action number 1

of Draw Event

for object oNode:



Variable oNode.yy(100003, -2147483648) not set before reading it.

at gml_Object_oNode_DrawEvent_1 (line 3) - draw_text(xx + 4, yy + 4, string(ds_list_size(neighbors)))

############################################################################################



what does it mean and how do I fix it I've spent two days trying and all I know is that the code below has something to do with it because when I take it out it works but is incomplete. all this code is an action under a draw event

draw_text(xx + 4, yy + 4, string(ds_list_size(neighbors)))

whole page below

draw_self();

draw_text(xx + 4, yy + 4, string(ds_list_size(neighbors)))
 

Perseus

Not Medusa
Forum Staff
Moderator
The error message says that yy hasn't been declared. Declare it the way you declared xx and post the entire code.
 
K

kingvamez

Guest
Im sory for the question im fairly new to this compared to other people but does that mean I should create a seperate line to declare yy or something
 
K

kingvamez

Guest
Is this it sorry if its the wrong code

globalvar map;

mapWidth = room_width/GRID_SIZE;
mapHeight = room_height/GRID_SIZE;

//create node;
for(xx = 0; xx < mapWidth; xx += 1) {
for(yy = 0; yy < mapHeight; yy += 1){
map[xx, yy] = instance_create(xx * GRID_SIZE, yy * GRID_SIZE, oNode);
}
}

//population neighbor lists!
for(xx = 0; xx < mapWidth; xx += 1){
for(yy = 0; yy < mapHeight; yy += 1){

node = map[xx, yy];

//add left neighbor
if (xx > 0){
ds_list_add(node.neighbors, map[xx - 1, yy]);
}

//add right neighbor

if(xx < mapWidth - 1){
ds_list_add(node.neighbors, map[xx + 1, yy]);
}

//add top neighbor

if(yy > 0){
ds_list_add(node.neighbors, map[xx, yy - 1]);
}

//add bottom neighbor

if(yy < mapHeight - 1){
ds_list_add(node.neighbors, map[xx, yy + 1]);
}

}

}

neighbors = ds_list_create();
 
Last edited by a moderator:
K

kingvamez

Guest
mapHeight I think

upload_2016-12-30_2-50-42.png

heres a picture


MOD EDIT: Triple post merged. Please use the EDIT button rather than post multiple times between replies from other users.
 

Attachments

Last edited by a moderator:

Bingdom

Googledom
globalvar map;

mapWidth = room_width/GRID_SIZE;
mapHeight = room_height/GRID_SIZE;

//create node;
for(xx = 0; xx < mapWidth; xx += 1) {
for(yy = 0; yy < mapHeight; yy += 1){
map[xx, yy] = instance_create(xx * GRID_SIZE, yy * GRID_SIZE, oNode);
}
}

//population neighbor lists!
for(xx = 0; xx < mapWidth; xx += 1){
for(yy = 0; yy < mapHeight; yy += 1){

node = map[xx, yy];

//add left neighbor
if (xx > 0){
ds_list_add(node.neighbors, map[xx - 1, yy]);
}

//add right neighbor

if(xx < mapWidth - 1){
ds_list_add(node.neighbors, map[xx + 1, yy]);
}

//add top neighbor

if(yy > 0){
ds_list_add(node.neighbors, map[xx, yy - 1]);
}

//add bottom neighbor

if(yy < mapHeight - 1){
ds_list_add(node.neighbors, map[xx, yy + 1]);
}

}

}
Where is all of this located? It should be in the create event.
 
K

kingvamez

Guest
it is under create event but draw_self();

draw_text(xx + 4, yy + 4, string(ds_list_size(neighbors))) is under draw
 

Bingdom

Googledom
Does oNode have a sprite assigned to it?
You will get errors if you don't have a sprite assigned to it (because you're using draw_self(), no sprite to draw), but I don't remember it showing that type of issue. (if it is that issue).

If it does, you may be drawing too many sprites. Try just drawing a bunch of lines instead.
 
K

kingvamez

Guest
so instead of drawing a sprite just draw a bunch of lines how many lines should i draw
 

Bingdom

Googledom
In your main object (draw event), do this:
Code:
draw_set_colour(c_black);
xx=0;
repeat( mapHeight ){
draw_line(xx,0,xx,room_height);
xx+=GRID_SIZE;
}
yy=0;
repeat( mapWidth ){
draw_line(0,yy,room_width,yy);
yy+=GRID_SIZE;
}
BTW, does the code you showed us run in oNode itself? Otherwise, you will be stuck in an infinite loop.
 
K

kingvamez

Guest
so by drawing lines do i draw lines where the sprite would be like open up sNode and draw a line instead of a square or do I do something else

sorry didnt see your post ill try the code that was sent
the draw self runs in onode
 
Last edited by a moderator:

Bingdom

Googledom
I mean the create event. Does this create event code run in oNode? If so, it will be stuck in an infinite loop because it's constantly creating itself in the create event.
 
K

kingvamez

Guest
the create event does run in oNode

where should i move the create event to then
 
Last edited by a moderator:

Bingdom

Googledom
Create a new object, call it oInit or oController. Put the create code inside the new object. When creating the oNode, assign it a string instead of making it read from a list.
 

Bingdom

Googledom
Actually, that's it.
You can even scrap using draw_line and use draw_self() instead.

The issue was that you were creating a infinite loop of oNode.
 
K

kingvamez

Guest
I put it in and there is an error in a different file oGame
############################################################################################
FATAL ERROR in
action number 1
of Create Event
for object oGame:

Variable oNode.neighbors(100002, -2147483648) not set before reading it.
at gml_Object_oGame_CreateEvent_1 (line 27) - ds_list_add(node.neighbors, map[xx + 1, yy]);
############################################################################################
 
K

kingvamez

Guest
globalvar map;

mapWidth = room_width/GRID_SIZE;
mapHeight = room_height/GRID_SIZE;

//create node;
for(xx = 0; xx < mapWidth; xx += 1) {
for(yy = 0; yy < mapHeight; yy += 1){
map[xx, yy] = instance_create(xx * GRID_SIZE, yy * GRID_SIZE, oNode);
}
}

//population neighbor lists!
for(xx = 0; xx < mapWidth; xx += 1){
for(yy = 0; yy < mapHeight; yy += 1){

node = map[xx, yy];

//add left neighbor
if (xx > 0){
ds_list_add(node.neighbors, map[xx - 1, yy]);
}

//add right neighbor

if(xx < mapWidth - 1){
ds_list_add(node.neighbors, map[xx + 1, yy]);
}

//add top neighbor

if(yy > 0){
ds_list_add(node.neighbors, map[xx, yy - 1]);
}

//add bottom neighbor

if(yy < mapHeight - 1){
ds_list_add(node.neighbors, map[xx, yy + 1]);
}

}

}
 
K

kingvamez

Guest
this is under oGame in debug mode and its only his one line of code
 
Top