Spawning problem

Hello

I'm using this code in an alarm to spawn four enemies, one real, the others fake. However, it only spawns all four when the real enemy spawns at point 0.

I am likely just making a simple coding error somewhere, but any help to fix this would be appreciated.

spawn_point=choose(0,1,2,3)
instance_create_layer(xx[spawn_point],yy[spawn_point],"instances", ob_en_ck_left_ice_poo)
if ob_en_ck_left_ice_poo=spawn_point=0{
spawn_point=(1)
instance_create_layer(xx[spawn_point],yy[spawn_point],"instances", ob_en_ck_left_ice_poo_fake)
spawn_point=(2)
instance_create_layer(xx[spawn_point],yy[spawn_point],"instances", ob_en_ck_left_ice_poo_fake)
spawn_point=(3)
instance_create_layer(xx[spawn_point],yy[spawn_point],"instances", ob_en_ck_left_ice_poo_fake)
}

if ob_en_ck_left_ice_poo=spawn_point=1{
spawn_point=(2)
instance_create_layer(xx[spawn_point],yy[spawn_point],"instances", ob_en_ck_left_ice_poo_fake)
spawn_point=(3)
instance_create_layer(xx[spawn_point],yy[spawn_point],"instances", ob_en_ck_left_ice_poo_fake)
spawn_point=(0)
instance_create_layer(xx[spawn_point],yy[spawn_point],"instances", ob_en_ck_left_ice_poo_fake)
}
if ob_en_ck_left_ice_poo=spawn_point=2{
spawn_point=(0)
instance_create_layer(xx[spawn_point],yy[spawn_point],"instances", ob_en_ck_left_ice_poo_fake)
spawn_point=(1)
instance_create_layer(xx[spawn_point],yy[spawn_point],"instances", ob_en_ck_left_ice_poo_fake)
spawn_point=(3)
instance_create_layer(xx[spawn_point],yy[spawn_point],"instances", ob_en_ck_left_ice_poo_fake)
}
if ob_en_ck_left_ice_poo=spawn_point=3{
spawn_point=(0)
instance_create_layer(xx[spawn_point],yy[spawn_point],"instances", ob_en_ck_left_ice_poo_fake)
spawn_point=(1)
instance_create_layer(xx[spawn_point],yy[spawn_point],"instances", ob_en_ck_left_ice_poo_fake)
spawn_point=(2)
instance_create_layer(xx[spawn_point],yy[spawn_point],"instances", ob_en_ck_left_ice_poo_fake)
}
 

jo-thijs

Member
Hello

I'm using this code in an alarm to spawn four enemies, one real, the others fake. However, it only spawns all four when the real enemy spawns at point 0.

I am likely just making a simple coding error somewhere, but any help to fix this would be appreciated.

spawn_point=choose(0,1,2,3)
instance_create_layer(xx[spawn_point],yy[spawn_point],"instances", ob_en_ck_left_ice_poo)
if ob_en_ck_left_ice_poo=spawn_point=0{
spawn_point=(1)
instance_create_layer(xx[spawn_point],yy[spawn_point],"instances", ob_en_ck_left_ice_poo_fake)
spawn_point=(2)
instance_create_layer(xx[spawn_point],yy[spawn_point],"instances", ob_en_ck_left_ice_poo_fake)
spawn_point=(3)
instance_create_layer(xx[spawn_point],yy[spawn_point],"instances", ob_en_ck_left_ice_poo_fake)
}

if ob_en_ck_left_ice_poo=spawn_point=1{
spawn_point=(2)
instance_create_layer(xx[spawn_point],yy[spawn_point],"instances", ob_en_ck_left_ice_poo_fake)
spawn_point=(3)
instance_create_layer(xx[spawn_point],yy[spawn_point],"instances", ob_en_ck_left_ice_poo_fake)
spawn_point=(0)
instance_create_layer(xx[spawn_point],yy[spawn_point],"instances", ob_en_ck_left_ice_poo_fake)
}
if ob_en_ck_left_ice_poo=spawn_point=2{
spawn_point=(0)
instance_create_layer(xx[spawn_point],yy[spawn_point],"instances", ob_en_ck_left_ice_poo_fake)
spawn_point=(1)
instance_create_layer(xx[spawn_point],yy[spawn_point],"instances", ob_en_ck_left_ice_poo_fake)
spawn_point=(3)
instance_create_layer(xx[spawn_point],yy[spawn_point],"instances", ob_en_ck_left_ice_poo_fake)
}
if ob_en_ck_left_ice_poo=spawn_point=3{
spawn_point=(0)
instance_create_layer(xx[spawn_point],yy[spawn_point],"instances", ob_en_ck_left_ice_poo_fake)
spawn_point=(1)
instance_create_layer(xx[spawn_point],yy[spawn_point],"instances", ob_en_ck_left_ice_poo_fake)
spawn_point=(2)
instance_create_layer(xx[spawn_point],yy[spawn_point],"instances", ob_en_ck_left_ice_poo_fake)
}
These 4 lines don't make sense:
Code:
if ob_en_ck_left_ice_poo=spawn_point=0{
Code:
if ob_en_ck_left_ice_poo=spawn_point=1{
Code:
if ob_en_ck_left_ice_poo=spawn_point=2{
Code:
if ob_en_ck_left_ice_poo=spawn_point=3{
GameMaker gets confused and interpretes those as:
Code:
if (ob_en_ck_left_ice_poo == spawn_point) == 0 {
Code:
if (ob_en_ck_left_ice_poo == spawn_point) == 1 {
Code:
if (ob_en_ck_left_ice_poo == spawn_point) == 2 {
Code:
if (ob_en_ck_left_ice_poo == spawn_point) == 3 {
A == B is a function that returns 1 if A equals B and 0 otherwise.
As a result, A == B can never be 2 or 3,
so the condition in these 2 lines:
Code:
if (ob_en_ck_left_ice_poo == spawn_point) == 2 {
Code:
if (ob_en_ck_left_ice_poo == spawn_point) == 3 {
is always false.

ob_en_ck_left_ice_poo is an object index and my guess is that he object doesn't occur as one of the first 2 objects in your resource tree.
An object index is actually a number, equal to the amount of preceding objects in the resource tree.
If there are at least 3 objects before ob_en_ck_left_ice_poo, then the condition of this line:
Code:
if (ob_en_ck_left_ice_poo == spawn_point) == 1 {
is also always false and the condition of this line:
Code:
if (ob_en_ck_left_ice_poo == spawn_point) == 0 {
is always true.

Now, as to fix your code, you should entirely rewrite it to:
Code:
var spawn_point == irandom(3);

for(var i = 0; i < 4; ++i) {
    instance_create_layer(xx[i], yy[i], "instances",
        i == spawn_point ? ob_en_ck_left_ice_poo : ob_en_ck_left_ice_poo_fake);
}
 
These 4 lines don't make sense:
Code:
if ob_en_ck_left_ice_poo=spawn_point=0{
Code:
if ob_en_ck_left_ice_poo=spawn_point=1{
Code:
if ob_en_ck_left_ice_poo=spawn_point=2{
Code:
if ob_en_ck_left_ice_poo=spawn_point=3{
GameMaker gets confused and interpretes those as:
Code:
if (ob_en_ck_left_ice_poo == spawn_point) == 0 {
Code:
if (ob_en_ck_left_ice_poo == spawn_point) == 1 {
Code:
if (ob_en_ck_left_ice_poo == spawn_point) == 2 {
Code:
if (ob_en_ck_left_ice_poo == spawn_point) == 3 {
A == B is a function that returns 1 if A equals B and 0 otherwise.
As a result, A == B can never be 2 or 3,
so the condition in these 2 lines:
Code:
if (ob_en_ck_left_ice_poo == spawn_point) == 2 {
Code:
if (ob_en_ck_left_ice_poo == spawn_point) == 3 {
is always false.

ob_en_ck_left_ice_poo is an object index and my guess is that he object doesn't occur as one of the first 2 objects in your resource tree.
An object index is actually a number, equal to the amount of preceding objects in the resource tree.
If there are at least 3 objects before ob_en_ck_left_ice_poo, then the condition of this line:
Code:
if (ob_en_ck_left_ice_poo == spawn_point) == 1 {
is also always false and the condition of this line:
Code:
if (ob_en_ck_left_ice_poo == spawn_point) == 0 {
is always true.

Now, as to fix your code, you should entirely rewrite it to:
Code:
var spawn_point == irandom(3);

for(var i = 0; i < 4; ++i) {
    instance_create_layer(xx[i], yy[i], "instances",
        i == spawn_point ? ob_en_ck_left_ice_poo : ob_en_ck_left_ice_poo_fake);
}
Thank you. So my codes were basically irrelevant, as it was saying if ob_en_ck_left_ice_poo was equal to the spawn point it equals one in the resource tree, which would be a different resource? And this basically had no consequence in the game.

If you have time would you mind saying what the rewrite does? I get you create a variable called spawnpoint, which has 3 random positions, but the next line I'm not sure of, and why use irandom?

No worries if you don't have the time, and thanks again.
 
Top