Legacy GM Choose random instance_create inside Alarm?

J

JACC

Guest
(
instance_create(64,16,asset_object_ammo),
instance_create(144,32,asset_object_ammo),
instance_create(208,32,asset_object_ammo),
instance_create(288,16,asset_object_ammo),
instance_create(160,80,asset_object_ammo),
instance_create(192,80,asset_object_ammo),
instance_create(160,144,asset_object_ammo),
instance_create(192,144,asset_object_ammo),
instance_create(80,112,asset_object_ammo),
instance_create(272,112,asset_object_ammo),
instance_create(96,176,asset_object_ammo),
instance_create(256,176,asset_object_ammo)
)
alarm[1] = 120



I have this code on alarm[0]. How can I go about and make the alarm trigger one of these instance create at random?
 
P

PandaPenguin

Guest
(
instance_create(64,16,asset_object_ammo),
instance_create(144,32,asset_object_ammo),
instance_create(208,32,asset_object_ammo),
instance_create(288,16,asset_object_ammo),
instance_create(160,80,asset_object_ammo),
instance_create(192,80,asset_object_ammo),
instance_create(160,144,asset_object_ammo),
instance_create(192,144,asset_object_ammo),
instance_create(80,112,asset_object_ammo),
instance_create(272,112,asset_object_ammo),
instance_create(96,176,asset_object_ammo),
instance_create(256,176,asset_object_ammo)
)
alarm[1] = 120



I have this code on alarm[0]. How can I go about and make the alarm trigger one of these instance create at random?
randomize the X and Y coordinates of it when creating just one instance
I would use irandom_range(minimum X, maximum X) and same for Y

alternatively if it has to be a specific set of these coordinates fill them in an array at the [create event] like this

Code:
ammoX[0] = 64;
ammoY[0] = 16;

ammoX[1] = 144;
ammoY[1] = 32;

.
.
.
and in the alarm[0] event you just pick a random set out of these arrays like this:

Code:
var ammoSet = irandom(your maximum number of ammo positons - 1)

instance_create(ammoX[ammoSet], ammoY[ammoSet], asset_object_ammo)
 
Last edited by a moderator:
J

JACC

Guest
randomize the X and Y coordinates of it when creating just one instance
I would use irandom_range(minimum X, maximum X) and same for Y

alternatively if it has to be a specific set of these coordinates fill them in an array at the [create event] like this

Code:
ammoX[0] = 64;
ammoY[0] = 16;

ammoX[1] = 144;
ammoY[1] = 32;

.
.
.
and in the alarm[0] event you just pick a random set out of these arrays like this:

Code:
var ammoSet = irandom(your maximum number of ammo positons - 1)

instance_create(ammoX[ammoSet], ammoY[ammoSet], asset_object_ammo)
Worked! I was in the middle of doing this thought

spawner = random(11)

if spawner = 0
{
instance_create(#,#,object_name.)
}

if spawner = 1
{
instance_create(#,#,object_name.)
}

idk if it was going to work but your method is more clean! Thank you!
 
P

PandaPenguin

Guest
Worked! I was in the middle of doing this thought

spawner = random(11)

if spawner = 0
{
instance_create(#,#,object_name.)
}

if spawner = 1
{
instance_create(#,#,object_name.)
}

idk if it was going to work but your method is more clean! Thank you!
well... it would have worked somehow I guess but I see some "potential pitfalls" in this code^^

first thing I noticed right away: you use random(11)
while it is not wrong to use it I would use irandom instead because random gives you any decimal between 0 and 11 and in the next step you only check for integer numbers (if 0, if 1, ...)

second thing: it looks like you were going to put 12 IF statements there to check for all the possible random numbers from your random(11)
not wrong again but a switch() statement would be more appropriate

third: your comparison would not work this way... for the IF to check for anything you need 2 "=" so the if would have to look like this
if spawner == 1
 
J

JACC

Guest
well... it would have worked somehow I guess but I see some "potential pitfalls" in this code^^

first thing I noticed right away: you use random(11)
while it is not wrong to use it I would use irandom instead because random gives you any decimal between 0 and 11 and in the next step you only check for integer numbers (if 0, if 1, ...)

second thing: it looks like you were going to put 12 IF statements there to check for all the possible random numbers from your random(11)
not wrong again but a switch() statement would be more appropriate

third: your comparison would not work this way... for the IF to check for anything you need 2 "=" so the if would have to look like this
if spawner == 1
Interesting... Then I should perhaps ask if this is a correct way to choose from multiple items

instance_create(ammoX[ammoSet], ammoY[ammoSet], choose(asset_object_ammo, asset_object_shield, asset_object_doubledamage))

and I tried changing instance_create(ammoX[ammoSet], ammoY[ammoSet] to instance_create(ammoX[ammoSet + 8], ammoY[ammoSet +8]
to alleviate for the x and Y coordinates being off with the sprite being centered. but that didn't work
 
Last edited by a moderator:
P

PandaPenguin

Guest
Interesting... Then I should perhaps ask if this is a correct way to choose from multiple items

instance_create(ammoX[ammoSet], ammoY[ammoSet], choose(asset_object_ammo, asset_object_shield, asset_object_doubledamage))

and I tried changing instance_create(ammoX[ammoSet], ammoY[ammoSet] to instance_create(ammoX[ammoSet + 8], ammoY[ammoSet +8]
to alleviate for the x and Y coordinates being off with the sprite being centered. but that didn't work
ok guessing from your new code you try to build a "loot" or "drop" system
that choose() should work fine!
but you put the +8 at the wrong spot, it has to be outside of the [ ]
Code:
instance_create(ammoX[ammoSet]+8, ammoY[ammoSet]+8, choose())
 
Top