Legacy GM Block will not change state/Singular block

T

Toy-sparker

Guest
I was trying to make it when enemy breaks the block until global.block1_hp = 0 then it should switches to broken state but it just glitches out. I've tried everything to fix it. Basically what happens is the enemy is stuck cause the block is still in full state and it won't change to destroy state.

Code:
///scr_blck_full
if(global.block1_hp = 6)
{

sprite_index = spr_block1_full;

}

if(global.block1_hp = 4)
{
image_index = 3;
sprite_index = spr_blck1_breaking;

}

if(global.block1_hp = 2)
{
image_index = 1;

}

if(global.block1_hp = 0)
{
state = scr_blck_destroy;
}

Code:
///scr_blck_buildup

image_speed = 0;
sprite_index = spr_block1_dmg;

//if(build_level = 1)
//{

if(global.build_time = 0)
{

image_index = 0;

}

if(global.build_time = 2)
{

image_index = 1;

}

if(global.build_time = 4)
{

image_index = 2;

}

if(global.build_time = 5)
{

image_index = 3;

}

if (global.build_time > 5)
{
blck_state = scr_blck_full;

}

//}
Code:
///scr_blck_destroy
sprite_index = spr_blck1_breaking;
image_index = 0;
 
Last edited by a moderator:
J

JTC

Guest
Hey mate,

first thing's first, I'd really recommend using code blocks in the forum, this makes it much easier for people like me to read.

Secondly, why are you using a global variable for the block's hp? This feels like a bad design choice unless there's some reason for it. For something like that, a local variable is probably much better.
I suspect the problem has something to do with this part:
Code:
if(global.block1_hp = 0)
{
state = scr_blck_destroy;
}
Does that condition ever evalute to true? Where is the code that adjusts the block's hp? Is it possible that it is reducing the hp below 0, and thus your block is never firing in the first place?
 
T

Toy-sparker

Guest
Hey mate,

first thing's first, I'd really recommend using code blocks in the forum, this makes it much easier for people like me to read.

Secondly, why are you using a global variable for the block's hp? This feels like a bad design choice unless there's some reason for it. For something like that, a local variable is probably much better.
I suspect the problem has something to do with this part:
Code:
if(global.block1_hp = 0)
{
state = scr_blck_destroy;
}
Does that condition ever evalute to true? Where is the code that adjusts the block's hp? Is it possible that it is reducing the hp below 0, and thus your block is never firing in the first place?




The instant var can not reach the enemy. in the enemies code. I made that way so i can put it in and put the damage settings


heres enemy damaging state to the block
Code:
///scr_enemy_eat

if(global.block1_hp > 0)
{

memetime += 1;
if(memetime = 120)
{
memetime = 0;
global.block1_hp -= 1;
audio_play_sound(snd_blockdmg,6,false)
}
}

if(global.block1_hp = 0)
{

memestate = scr_meme_move;

}

heres the blocks create. The player can build a block. and thus they start as building up.

Code:
///scr_block1_full

state = scr_blck_buildup;
global.block1_hp = 6;

i attempted to replace the state = scr_blck_destroy with instance destroy... it didn't do anything
 
Last edited by a moderator:
J

JTC

Guest
I'm sorry, this is quite difficult for me to follow. Is the state of the object even changing? You can check this with the debugger.
 
T

Toy-sparker

Guest
I'm sorry, this is quite difficult for me to follow. Is the state of the object even changing? You can check this with the debugger.
I recoded some of it. yes but the instance destroy is confusing me. I can't get it to destroy itself

There was a slight typo in the states. So I had to retype some of it. But I didn't add anything specifying about the instance stopping itself from destroying. I don't know if I keep missing something.
 
Last edited by a moderator:
T

Toy-sparker

Guest
NVM, I somehow fixed it. added this

with(obj_block_1) instance_destroy();

to the destroy script. So this thread now closed.
 

TheouAegis

Member
You do realize that if you have more than one obj_block_1 in your game at any time, that code will no longer work. Your code will only work for you so long as there is only a single block1 instance in the room at any time.

And enemies can access the variables inside of your block object just fine. As long as you do not put VAR in front of your variables, then anything can read that variable. Making it a global variable it's one of the contributing factors to why you can only have one instance of that block object in the room at any.
 
T

Toy-sparker

Guest
Yeah. I've realized that.

I'm still learning gamemaker studio. And I understand people might think I suck at it. I just wanna get help or atleast the best advice. The thing is. I can't figure a possible way of making one instance get destroyed while the others aren't. I wanna know what the best option is in this current state of the enemy destroying a singular block
 
A

AnimusRex

Guest
Stop using the health variable for the block as a global variable, set it for whatever block in the create event, then have with it gets to zero, instance_destroy();
and it will destroy just itself, not all instances of the same name.
 
Top