Jump to content


Photo

life variable


  • Please log in to reply
9 replies to this topic

#1 litemaker96

litemaker96

    GMC Member

  • New Member
  • 6 posts
  • Version:GM8

Posted 11 March 2012 - 12:16 PM

I'm working now on a space game and i need that each enemy spaceship have their own life variable, so i gave to the obj "speceship" a lifebar.
but when i run the game and i shoot to a spaceship all the spaceship lose life.
how can i fix it?
  • 0

#2 .IB

.IB

    GMC Member

  • New Member
  • 38 posts

Posted 11 March 2012 - 12:19 PM

Are you using D&D? Or Gml? In which event are you putting the life bar?
  • 0

#3 DcoldSaviour77

DcoldSaviour77

    GMC Member

  • GMC Member
  • 255 posts
  • Version:GM8

Posted 11 March 2012 - 12:21 PM

I'm working now on a space game and i need that each enemy spaceship have their own life variable, so i gave to the obj "speceship" a lifebar.
but when i run the game and i shoot to a spaceship all the spaceship lose life.
how can i fix it?

The variable is it a local or a global?
  • 0

#4 litemaker96

litemaker96

    GMC Member

  • New Member
  • 6 posts
  • Version:GM8

Posted 11 March 2012 - 06:49 PM

for set life variable i used D&D
-the first time i put on "create" the icon "set life" to 100 not relative and then i put on draw event the icon "draw life bar" to....
During the game, while there is just one spaceship everything work, but when arrive the second spaceship and i shoot to the first, also the second lose 20 life points
-the second time i put on create a "set variable" icon and i wrote "global.sslife". no draw event.
But again when arrive the second spaceship i shoot to it and both explode... :confused:
  • 0

#5 TheouAegis

TheouAegis

    GMC Member

  • GMC Member
  • 4714 posts
  • Version:GM8

Posted 11 March 2012 - 07:09 PM

Never use global variables for instance-specific aspects. Health, player lives (in a multiplayer game), ammo, etc are all instance-specific.

If you are using D&D, you need to put in each ship a trigger for Collision With Bullet (or whatever your weapons are called) and set its life to -20 relative.
  • 2

#6 litemaker96

litemaker96

    GMC Member

  • New Member
  • 6 posts
  • Version:GM8

Posted 11 March 2012 - 08:40 PM

thanks for the advise, but as you can see in my nickname i've the lite edition because i want to test it before buy the pro....
but if you say that in the pro edition i can do it.. thanx :thumbsup:
  • 0

#7 litemaker96

litemaker96

    GMC Member

  • New Member
  • 6 posts
  • Version:GM8

Posted 11 March 2012 - 09:29 PM

I'm sorry, but i have to ask you another question that i didn't found in the forun (like i need)
How i can definite a local question (D&D but if you can't, explain me how in gml)
i put in create event set "local.life"
collision event (bullet) set "local.life" relative -2
if "local.life" equal to 0
-start of a block
destroy the istance
-end of a block
but when i run the game appear the messagge "unknow variable"
Why? :ermm:
  • 0

#8 GameGeisha

GameGeisha

    GameGeisha

  • GMC Member
  • 2747 posts
  • Version:GM:Studio

Posted 11 March 2012 - 09:34 PM

Just use life as is.

Creation event:
life = 5; //Example

Collision event with bullet
life -= 2;
if (life <= 0) {
  instance_destroy();
}

GameGeisha
  • 0

#9 litemaker96

litemaker96

    GMC Member

  • New Member
  • 6 posts
  • Version:GM8

Posted 11 March 2012 - 09:44 PM

thanx you very very very much, i worked on that problem for days :biggrin:
  • 0

#10 thespriteguy

thespriteguy

    GMC Member

  • New Member
  • 6 posts
  • Version:GM8

Posted 12 March 2012 - 01:20 AM

Hey also,
if you're interested in each ship having their own health bar you can put this code in their draw event:
{
draw_sprite_stretched(spr_healthbar1,0,x,y-however-far-above-the-ship,max_life,however-tall-the-bar-is);
draw_sprite_stretched(spr_healthbar1,0,x,y-however-far-above-the-ship,life,however-tall-the-bar-is)
}

sorry if there's a typo i'm doing this off the top of my head.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users