C
Cmi
Guest
So I have an object and it changes spirits. When The object spawns and say spirit is on 1 and another spawns and is on spirit 2 how do I make it so that the object that spawned first get destroyed by a key press that I assign it. Here is my code am not sure why it isn't working.
Create Event
Step
Create Event
Code:
//Randomize
randomize();
// Set total to equal the random number
total = irandom(2);
// Set image index equal total
if (total == 0){
total = 1;
}
image_index = total;
// set the image speed equal 0
image_speed = 0;
// Everytime an object is created add 1 to the global.left
global.left+=1;
Code:
var a = 0;
var b = 0;
var c = 0;
if (total == 1){
a = 1;
}
if (a == 1){
// Declare a variable called obj
var obj;
// Check if D has been pressed
if keyboard_check_pressed(ord('A')){
//get the first instance of the given object
obj = instance_find(obj_try, 0);
// Check if the object exists
if(obj != noone)
{
// Destory all instances of obj = instance_find(obj_d, 0)
with(obj)
{
// Add 1 to the score
global.score_1++;
// Destory the object
instance_destroy();
}
}
}
}
if (total == 2){
b = 1;
}
if (b == 1){
// Declare a variable called obj
var obj;
// Check if D has been pressed
if keyboard_check_pressed(ord('B')){
//get the first instance of the given object
obj = instance_find(obj_try, 0);
// Check if the object exists
if(obj != noone)
{
// Destory all instances of obj = instance_find(obj_d, 0)
with(obj)
{
// Add 1 to the score
global.score_1++;
// Destory the object
instance_destroy();
}
}
}
}