Variable woes

This forum is currently in read-only mode.
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • I am seriously getting myself confogulated with the variables i set for what seems to be a simple thing.My problem is this ,When the spaceship picks up a shield powerup then a text shows the shield's power as 99.

    At the start of the layout the shield must be set to 0.This is where things get confusing , You see when the asteroids hits the shield then the shield meter goes down and when the shield meter hits 0 then the shield is destroyed.Now the shield get's destroyed at the start of the layout every time.

    It's quite difficult to explain seeing that i suck at english ,so here is the cap instead.Will someone please help me to correct my problems.I do not know what to do anymore.It's quite a large cap file ,about 10 megs in size.

    Any help would be greatly appreciated.Below is the zipped cap file download.

    Asteroid woes download

  • Perhaps have something of a dummy variable for your player sprite on startup to control if the shield is active or not?

    Have it set at startup at ShieldActive=0

    And then have the events go:

    Start of layout

    -Set Player.Value(ShieldActive) to 0

    On collision with shield-pickup

    -Set Player.Value(ShieldActive) to 2

    If Player.Value(ShieldActive) equal to 2

    -spawn Shield Object

    -Set Player.Value(ShieldActive) to 1

    If ShieldActive = 1

    -On collision with Asteroid

    -Subtract x from Shield.Value(Energy)

    If Shield.Value(Energy) is less than or equal to 0

    -Destroy Shield

    -Set Player.Value(ShieldActive) to 0

    In that way, you have three states for Shield Active:

    0 No shield, waiting for powerup

    1 Shield is active, able to diminish and be destroyed

    2 Initially getting the shield powerup

    Does that work?

  • I will try your way Emperoring360.It makes more sense to me now.So the shield variable must have 3 states not two.I will let you know if it works.

  • Ok i have tried it but the shield refuses to stay with the ship.And remember i have an energy bar which is a tiledbackground,So if the shield is destroyed then the ship's energy is drained if it collides with an asteroid.When the asteroid collides with the ship then i set the width of the tiledbackground to -10 .

    Rock collides with ship / TiledBackground: Set width to TiledBackground.Width-10.Maybe i should start over and see if i can fix this somehow <img src="smileys/smiley19.gif" border="0" align="middle" />

    Thank's for the help so far.

  • What do you mean, refuses to stay with the ship?

    Do you have a set of events like

    If ShieldActive = 2

    -spawn Shield at Player.X, Player.Y (or wherever you want the shield)

    -set Shield.X, Shield.Y to Player.X, Player.Y

    If ShieldActive = 1

    -set Shield.X, Shield.Y to Player.X, Player.Y

    You have to set up an event that if a certain condition is met, the shield will always be at the image point of your ship.

    ----This might be over-complicating things, but you can also try things like this----

    Have the shield ALWAYS be with you, even from the start, and have three animations:

    ShieldActive = 0

    Animation name: Inactive

    ShieldActive = 1

    ShieldDefault

    ShieldActive = 2

    AcquiringShield

    That way, you can have it that the events check if a certain animation is playing the asteroids will affect it:

    If Shield animation ShieldDefault is playing

    On collision with asteroid

    -subtract x from energy

    Just a thought, though.

    As for your healthbar issues, I'm not sure. There are some tutorials in the classic section (under JamesX's tutorial list) that deal with health bars, if I remember correctly.

  • I got the shield to stay with the ship now.The problem i seem to have is with the different layouts now.The event's work's correct up until the last layout.Then things seem to get out of control ,My events are almost the same for each layout.Sometimes the shield attaches itself for no good reason , The score system keeps resseting etc...Too many to mention.

    I guess it's back to the coding board.These methods are so easy when i create them with Xna Game Studio.I am creating this game with different game making programs as i want to create it for mobile phones etc...

    Hopefully i will have more luck With Construct 2.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • That is why you should not have your events for each layout.

    You should have EVENT SHEETS, and include them for each of your layouts.

    Make an event sheet named "Control" or "Shield" or "Score" or anything, then go to your level layouts, right-click, and "Include Event Sheet"

    That way, all the controls are the same for each layout that has the include.

  • Ah ok i see.Thank's for the tip Emperoring360.I decided to ditch the shield powerup idea.The ship has a shield at the start of the level now.The powerup only replenishes the shield now.

    I created event sheets now for all the layouts and now everything seems to work correctly.It was the Wait object that made everything go haywire.

    Thank's once again for your tips and patience.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)