Having problems with Adding Lives

Game Editor comments and discussion.

Having problems with Adding Lives

Postby RippeR7420 » Tue Feb 21, 2012 6:43 pm

So this is what i'm doing...

Score->DrawActor->Script->
}
Code: Select all
if(Score.textNumber>=1000)
{
Lives.textNumber=Lives.textNumber+1;


I've tried putting this code in the Lives Actor under Draw Actor, but It still doesn't work..
The number just continuously rises.. on the other hand, when I put this code in the Create
Actor event, nothing happens at all.

I have a Variable for both, My Lives, and Score.

Anybody know what I'm doing wrong?
CURRENT PROJECTS:

-Olo: The Sword Shaman http://game-editor.com/forum/viewtopic.php?f=4&t=12919

-The Wrath of Blob: (On the back burner)

-StickMcGee - Blast to the Future http://game-editor.com/forum/viewtopic.php?f=4&t=13660
User avatar
RippeR7420
 
Posts: 391
Joined: Mon Apr 27, 2009 4:16 pm
Location: Salt Lake City, Utah.
Score: 23 Give a positive score

Re: Having problems with Adding Lives

Postby skydereign » Tue Feb 21, 2012 8:12 pm

Ok, you need to come to learn when events trigger. A lot of using gE is knowing when certain events will trigger and which ones of those are appropriate for the tasks you want. In this case create actor only happens once, so would putting it there make sense? That bit of code only gets looked at once when the actor is created, so that means score has to already be 1000 when the actor is created.

Now draw actor happens every frame. Since you are checking for when score is greater than 1000, that could happen at any time, and therefore you would have to check every frame. But since draw events execute every frame this poses the following problem. If score is greater than 1000 then Lives will be increased every frame. That currently is what you are having problems with. There are a couple of ways of fixing this. If score is allowed to be reset (as in lowering it by 1000 is okay) then doing that will work. But since you are using a text actor to display it probably that isn't the case. You could do something like this though (create a variable called next_life).
Code: Select all
if(score>next_life)
{
    next_life+=1000;
    lives++;
}

Two things about that, next_life will need to be set to 1000 at the start of your game, the other thing is I recommend you stay away from using textNumbers like that. They aren't a good replacement for real variables, as there have been many reports of textNumbers causing unpredictable behavior. So, instead you should only set textNumber to something, instead of using it in comparisons. You say you have said variables so use them. Usually people just add a draw event to their text actors that displays their variable.
life_display -> Draw Actor -> Script Editor
Code: Select all
textNumber=lives;
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Having problems with Adding Lives

Postby RippeR7420 » Tue Feb 21, 2012 11:37 pm

ahh, okay... How would you recommend doing a "Lives" system?
CURRENT PROJECTS:

-Olo: The Sword Shaman http://game-editor.com/forum/viewtopic.php?f=4&t=12919

-The Wrath of Blob: (On the back burner)

-StickMcGee - Blast to the Future http://game-editor.com/forum/viewtopic.php?f=4&t=13660
User avatar
RippeR7420
 
Posts: 391
Joined: Mon Apr 27, 2009 4:16 pm
Location: Salt Lake City, Utah.
Score: 23 Give a positive score

Re: Having problems with Adding Lives

Postby skydereign » Tue Feb 21, 2012 11:42 pm

What do you mean? Just have a variable that holds the number of lives and use it accordingly. If you need to increase or decrease lives than you can just change the variable. If you need to check if lives is greater than zero (the player has another life) just use an if statement checking the variable. Lastly if you want to display it you can set a text actor's textNumber variable equal to it. You handle it like any other variable you deal with, except since this variable is one you want to be viewable by the player you would use textNumber to display it.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Having problems with Adding Lives

Postby RippeR7420 » Tue Feb 21, 2012 11:46 pm

I guess I'm just not understanding how to add +1 to the variable...
CURRENT PROJECTS:

-Olo: The Sword Shaman http://game-editor.com/forum/viewtopic.php?f=4&t=12919

-The Wrath of Blob: (On the back burner)

-StickMcGee - Blast to the Future http://game-editor.com/forum/viewtopic.php?f=4&t=13660
User avatar
RippeR7420
 
Posts: 391
Joined: Mon Apr 27, 2009 4:16 pm
Location: Salt Lake City, Utah.
Score: 23 Give a positive score

Re: Having problems with Adding Lives

Postby skydereign » Tue Feb 21, 2012 11:56 pm

How have you been doing movement all this time? I feel like you're probably over thinking this.
Code: Select all
x+=1; // this increases x by 1
x = x + 1; // so does this
x++; // and so does this

That's how you increase the value stored in variables (decreasing would just be using - instead of +).
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Having problems with Adding Lives

Postby RippeR7420 » Wed Feb 22, 2012 12:32 am

haha maybe. What I am doing is this;

Lives->Draw Actor-> Script->

Code: Select all
if(Score.textNumber>=1000)
{
Lives.textNumber+=1;
}


So, I have a variable set up for my lives called "PlayerLives". I use it for SaveVars and LoadVars only... How do I incorporate into this draw actor?..
CURRENT PROJECTS:

-Olo: The Sword Shaman http://game-editor.com/forum/viewtopic.php?f=4&t=12919

-The Wrath of Blob: (On the back burner)

-StickMcGee - Blast to the Future http://game-editor.com/forum/viewtopic.php?f=4&t=13660
User avatar
RippeR7420
 
Posts: 391
Joined: Mon Apr 27, 2009 4:16 pm
Location: Salt Lake City, Utah.
Score: 23 Give a positive score

Re: Having problems with Adding Lives

Postby RippeR7420 » Wed Feb 22, 2012 12:34 am

How do I set a Variable to hold the number of Lives?
CURRENT PROJECTS:

-Olo: The Sword Shaman http://game-editor.com/forum/viewtopic.php?f=4&t=12919

-The Wrath of Blob: (On the back burner)

-StickMcGee - Blast to the Future http://game-editor.com/forum/viewtopic.php?f=4&t=13660
User avatar
RippeR7420
 
Posts: 391
Joined: Mon Apr 27, 2009 4:16 pm
Location: Salt Lake City, Utah.
Score: 23 Give a positive score

Re: Having problems with Adding Lives

Postby skydereign » Wed Feb 22, 2012 12:45 am

You know how to do it. You've been doing it for your textNumber variables as well as your variables you have for saveVars and loadVars.
Code: Select all
Lives = 3; // sets Lives to 3
Lives++; // increases Lives by 1
Lives+=2; // increases Lives by 2
Lives--; // decreases Lives by 1

if(Lives>0)
{
    // checks if the player still has some Lives left
}
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Having problems with Adding Lives

Postby RippeR7420 » Wed Feb 22, 2012 1:19 am

wow I'm feeling really stupid because I can't figure this out. :oops:
So I do something like this?;

Lives->Create->Script->
Code: Select all
PlayerLives=Lives.textNumber;
PlayerLives = 3;


and then this;

Lives->Draw->Script->
Code: Select all
if(Score.textNumber>=1000)
{
PlayerLIves++;
}


something like this?...
CURRENT PROJECTS:

-Olo: The Sword Shaman http://game-editor.com/forum/viewtopic.php?f=4&t=12919

-The Wrath of Blob: (On the back burner)

-StickMcGee - Blast to the Future http://game-editor.com/forum/viewtopic.php?f=4&t=13660
User avatar
RippeR7420
 
Posts: 391
Joined: Mon Apr 27, 2009 4:16 pm
Location: Salt Lake City, Utah.
Score: 23 Give a positive score

Re: Having problems with Adding Lives

Postby skydereign » Wed Feb 22, 2012 7:13 am

In all honesty you need to relearn variables. You are trying to understand something but only grasping a very small portion of it. This probably comes from copying bits of code and not truly understanding how it works. So I ask, do you know what a variable is? If you want we can continue this in pm and I can walk you through the basics.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest