A
azuarf
Guest
I am trying to generate random tiles for my map. But it only makes one instance and thats at the middle of the screen far away from where the first instance should be. Here is the code that i used.
xi = 0
yi = 8000
for (i = 0; i < 2000; i+=1)
{
rand = random_range(1,3);
if (rand = 1)
{
instance_create(xi,yi,obj_floor1);
}
else if (rand = 2)
{
instance_create(xi,yi,obj_floor2);
}
else if (rand = 3)
{
instance_create(xi,yi,obj_floor3);
}
xi += 64;
if (xi >= 1920)
{
yi += 64;
xi = 0;
}
}
This code is in the left mouse button event. Can someone explain why this dose not work? I am an amature. i tried drawing sprites instead of creating instances but it dose somewhat the same thing. a single sprite flickers at where the instance is in the pic and then nothing. i thought the problem might be because of draw event so i tried creating instance. heres the code i used for drawing sprite. its the same as the one above though.
xi = 0
yi = 8000
if(global.adv1_state = 1)
{
for(i = 0; i <2000; i += 1
{
if (global.adv1_array = 1)
{
draw_sprite(spr_bg1,0,xi,yi);
}
else if(global.adv1_array = 2)
{
draw_sprite(spr_bg2,0,xi,yi);
}
else if (global.adv1_array = 3)
{
draw_sprite(spr_bg3,0,xi,yi);
}
xi += 64;
if(xi >= 1920)
{
yi += 64;
xi = 0;
}
}
}
the adv1_array is generated in a mouse button event. Am i using arrays in a wrong way? i am fairely new to programing. Thanks for reading this.
xi = 0
yi = 8000
for (i = 0; i < 2000; i+=1)
{
rand = random_range(1,3);
if (rand = 1)
{
instance_create(xi,yi,obj_floor1);
}
else if (rand = 2)
{
instance_create(xi,yi,obj_floor2);
}
else if (rand = 3)
{
instance_create(xi,yi,obj_floor3);
}
xi += 64;
if (xi >= 1920)
{
yi += 64;
xi = 0;
}
}
This code is in the left mouse button event. Can someone explain why this dose not work? I am an amature. i tried drawing sprites instead of creating instances but it dose somewhat the same thing. a single sprite flickers at where the instance is in the pic and then nothing. i thought the problem might be because of draw event so i tried creating instance. heres the code i used for drawing sprite. its the same as the one above though.
xi = 0
yi = 8000
if(global.adv1_state = 1)
{
for(i = 0; i <2000; i += 1
{
if (global.adv1_array = 1)
{
draw_sprite(spr_bg1,0,xi,yi);
}
else if(global.adv1_array = 2)
{
draw_sprite(spr_bg2,0,xi,yi);
}
else if (global.adv1_array = 3)
{
draw_sprite(spr_bg3,0,xi,yi);
}
xi += 64;
if(xi >= 1920)
{
yi += 64;
xi = 0;
}
}
}
the adv1_array is generated in a mouse button event. Am i using arrays in a wrong way? i am fairely new to programing. Thanks for reading this.
Attachments
-
65 KB Views: 6
Last edited by a moderator: