Why the object is not creating?

S

Shahil

Guest
Room Creation Code::


var i, file;

file = file_text_open_read("level_1.lvl");

i = 0 ;

while (!file_text_eof(file)) {
object = file_text_read_string(file); // object name
file_text_readln(file);
object_x = file_text_read_real(file); // object x
file_text_readln(file);
object_y = file_text_read_real(file); // object y
file_text_readln(file);


if(instance_exists(object)) {
instance_create(real(object_x),real(object_y),object);
} else {
show_message("Name: " + object + " X: " + string(object_x) + " Y: " + string(object_y))
}



i = i + 3;
}


file_text_close(file);


Level 1 File:


obj_goomba
128
48
obj_maskman
384
64

The object is not creating in the room...


if i write the code instance_create(90,90,obj_goomba) it create but when i try to do from the above file it does not create the object
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Object IDs are NOT strings, so you need to use the "asset_" function to turn the string into the proper object ID variable. Also, the check for "instance_exists" seems odd, as no instance of the object will exist and so no instance will be created anyway. you might want to make that a NOT check instead... ;)
 

Mick

Member
You are checking instance_exists before creating the instance. This will return false (if there is no instance of that object in the room) and no instance of the object will be created. In other words, you are mixing up objects and instances. Instead of the instance_exists function, use asset_get_index(...).

Edit: I wrote this on my mobile so Nocturne's answer arrived meanwhile, a few decades earlier.
 
S

Shahil

Guest
You are checking instance_exists before creating the instance. This will return false (if there is no instance of that object in the room) and no instance of the object will be created. In other words, you are mixing up objects and instances. Instead of the instance_exists function, use asset_get_index(...).

Edit: I wrote this on my mobile so Nocturne's answer arrived meanwhile, a few decades earlier.
I am using gamemaker 8 pro.. the function is not available
 
S

Shahil

Guest
Then create your own script that emulates it.
Code:
switch (argument0) {
  case "obj_goomba": return obj_goomba;
  case "obj_maskman": return obj_maskman;
  /* ... */
  default: return -1;
}


Thanks

Why this is not working draw_sprite_ext(sprite_index,-1,round(x),y,direct,image_yscale,0,c_white,1) ?
 

FrostyCat

Member
Why this is not working draw_sprite_ext(sprite_index,-1,round(x),y,direct,image_yscale,0,c_white,1) ?
There are plenty of reasons why that wouldn't work:
  • You placed it outside the Draw event
  • The object has no assigned sprite
  • direct or image_yscale has been set to 0
  • The position to draw at is outside the room or behind something else
You need to look at that line as part of the whole and think about whether it makes sense there. There is no point in fixating on that one line alone.
 
Top