• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Help - rusty on my GML coding

DreTazzz

Member
Hi there,

Would anyone know WHY it would show my health bar in one room, but not another room? It is the exact same coding, but I just have it popping up in another room. It is driving me nuts. To be specific - the healthbar frame shows - but not the actual ascending/descending health bar (which i have coded same - as its own object).

I checked the layers, and they are the same. I created a Controller that creates my healthbar object on an alarm. Everything matches in both rooms. Ideas? Suggestions? Shout outs? :-|


upload_2019-10-22_12-49-3.png


View attachment 27146

upload_2019-10-22_12-52-14.png
 

Yal

šŸ§ *penguin noises*
GMC Elder
Is the health the same in both rooms? If it's zero, of course you won't see the healthbar even if it's there.
 

Thultex

Member
Gradually debug and check if the hp variable is actually transfered to the object. Look at the numbers of the transformations, either giving them out or storing them localy and check on debug. The breakpoint/Msg will also show you if the object and the corresponding event are actually active.
 

curato

Member
make sure if you have a manager object that is supposed to carry over and manage stuff like that from room to room, make sure it is set to persistent so that it there to do it.
 

samspade

Member
This is a good situation for the debugger. If you're in GMS 2 you can even turn on real time debugging where it will update as you're going. That would allow you to see which instances actually exist and check their values.
 

DreTazzz

Member
Gradually debug and check if the hp variable is actually transfered to the object. Look at the numbers of the transformations, either giving them out or storing them localy and check on debug. The breakpoint/Msg will also show you if the object and the corresponding event are actually active.

Thank you so much for that advice - I am going to check that now. :)
 

DreTazzz

Member
make sure if you have a manager object that is supposed to carry over and manage stuff like that from room to room, make sure it is set to persistent so that it there to do it.
Thank you Curato. I will look into right now actually. :)
 

DreTazzz

Member
This is a good situation for the debugger. If you're in GMS 2 you can even turn on real time debugging where it will update as you're going. That would allow you to see which instances actually exist and check their values.

Thanks samspade. I am actually using GMS 1 - but I appreciate you for responding, nonetheless. :)
 

samspade

Member
Thanks samspade. I am actually using GMS 1 - but I appreciate you for responding, nonetheless. :)
GMS 1 debugger is also good and would show you what you need to know. It just doesn't have real time (I don't think) so you have to pause it.
 

DreTazzz

Member
Gradually debug and check if the hp variable is actually transfered to the object. Look at the numbers of the transformations, either giving them out or storing them localy and check on debug. The breakpoint/Msg will also show you if the object and the corresponding event are actually active.
Thultex, thanks sooooo much. The debugging idea worked. i saw exactly where my hp was showing as -30 in the other room, due to a code I had in a script. I fixed it. :) That leads to my next question - would you know how I can code this next scenario:

As example: (if object_A is in room_B, I want (hp =- 30), whenever object_C, object_D, or object_E enter that room I mentioned).

...and btw I am not using GMS 2.

Thank you.
 

DreTazzz

Member
GMS 1 debugger is also good and would show you what you need to know. It just doesn't have real time (I don't think) so you have to pause it.
samspade, thanks sooooo much as well for suggesting debugger. The debugging idea worked. That leads to my next question - would you know how I can code this next scenario:

As example: (if object_A is in room_B, I want (hp =- 30), whenever object_C, object_D, or object_E enter that room I mentioned).

...and again I am not using GMS 2. :)

Thank you.
 
R

robproctor83

Guest
DreTazzz, I have not been following your post too closely so forgive if I misunderstand, but couldn't you simply use if(instance_exists(obj_c))? Your not running two rooms at the same time, are you? If not, then I would suspect that should work.
 

DreTazzz

Member
DreTazzz, I have not been following your post too closely so forgive if I misunderstand, but couldn't you simply use if(instance_exists(obj_c))? Your not running two rooms at the same time, are you? If not, then I would suspect that should work.
Hi there - thanks for responding. No, I am only running one room at a time. I figured the "if (instance exists..." would work; however, I am unsure how to code the whole thing. Again the overall code I want reflects this:

(if object_A is in room_B, I want (hp =- 30), whenever object_C, object_D, or object_E enter that room I mentioned).

The c,d,e objects randomly pop in the room - at separate times. When they do - if the object A is in the room too at the same time, then I want the health to deplete by -30hp. Hope that makes sense. :)
 

Thultex

Member
Glad to help... carefull debugging can solve a LOT.

I usually work with Main Objects that control all that stuff. I have one central HUB containing all necessary information (persistent object) so I don't have to abuse globals. (obGame.hp would be the central object every object would access the hp). In GM you can go very lax and ask for the persistent Object from any object or you can just set the hp of all healthBars
Code:
var _hp = hp // local variables are object independent in any function
  with obHealthBar
    hp = _hp;
ANY object health bar will have their hp updated.
 

DreTazzz

Member
Glad to help... carefull debugging can solve a LOT.

I usually work with Main Objects that control all that stuff. I have one central HUB containing all necessary information (persistent object) so I don't have to abuse globals. (obGame.hp would be the central object every object would access the hp). In GM you can go very lax and ask for the persistent Object from any object or you can just set the hp of all healthBars
Code:
var _hp = hp // local variables are object independent in any function
  with obHealthBar
    hp = _hp;
ANY object health bar will have their hp updated.

Thanks for advice. I have used a main object, or controller before. But, in this case, how would you link all the things you mentioned to that one, main obj_hp, please? What I want is:

if object_A is in room_B - at the same time that - object_C, object_D, or object_E enter that room, then I want (hp =- 30).

:)
 
To be clear, are you looking to change object_A's HP to -30 (which is what hp =- 30 would do), or decrease its HP by 30 (which would be hp -= 30)? Either way, this should work (place it in the Create Event for objects C, D, and E, or a parent object of all three).

Code:
if(room = room_B)
   {
   if(instance_exists(object_A))
      {
      with(object_A)
              {
              hp =-30 //(or hp-=30, whichever you intended)
              }
        }
    }
Keep in mind, though, that if you have multiple instances of object_A, this will change the HP of all of them.
 

DreTazzz

Member
To be clear, are you looking to change object_A's HP to -30 (which is what hp =- 30 would do), or decrease its HP by 30 (which would be hp -= 30)? Either way, this should work (place it in the Create Event for objects C, D, and E, or a parent object of all three).

Code:
if(room = room_B)
   {
   if(instance_exists(object_A))
      {
      with(object_A)
              {
              hp =-30 //(or hp-=30, whichever you intended)
              }
        }
    }
Keep in mind, though, that if you have multiple instances of object_A, this will change the HP of all of them.
Hi there. Thank you so much! I am looking to decrease the Hp by 30. Thank you for the coding. I am going to check into that right now. :)
 

DreTazzz

Member
To be clear, are you looking to change object_A's HP to -30 (which is what hp =- 30 would do), or decrease its HP by 30 (which would be hp -= 30)? Either way, this should work (place it in the Create Event for objects C, D, and E, or a parent object of all three).

Code:
if(room = room_B)
   {
  
if(instance_exists(object_A))
Keep in mind, though, that if you have multiple instances of object_A, this will change the HP of all of them.

I was so stoked...sadly it is not working. In the Create Event of my objects C, D, and E, I entered what you wrote above - with the proper objects and room inserted. Suggestions?

scr_roomArrayVariables()

if(room = andreRoom[1])
{
if(instance_exists(obj_andreSleeping))
{
with(obj_andreSleeping)
{
global.rem_hp-=30
}
}
}
 
First of all, sorry it took me so long to get back to you on this. I ran the code in a test project, and it worked fine for me (with one slight change: if your health variable is global, you don't need the with statement). The only thing I can think of is that global.rem_hp is being changed or reset somewhere else in your code. Where else is it being referenced? I would especially look closely at any changes to the value occurring in alarms or step events. Its possible that the health IS decreasing but then being reset.
 
Top