Page 1 of 3

Score number as event activator

PostPosted: Tue May 23, 2006 5:32 pm
by Diana Kennedy
Ok, I am pretty annoying these days with all those new questions.

But I would like to know if there is a way to activate some events; i.e create actors, changing animation of an actor and so on, when a certain score number is reached. I would need this for scenarios like: shoot enough of the flying monsters and the big gate of the castle opens!

PostPosted: Tue May 23, 2006 6:16 pm
by Novice
1.Create an integer variable "MonstersKilled" and "Gate".

2.Every time a monster is killed increase the variable.

3.On the player actor put this in to script editor for Draw Actor:
Code: Select all
if (MonstersKilled==25&&Gate==0)
{
      SendActivationEvent("GateActor");
      Gate=1;
}

4.On the gates activation event do whatever you want.

There are many diferent ways to do this, this is the first one i tought of. Hope it helps. In case you were wondering the Gate variable is there just to stop the if statement from repeating itself.

PostPosted: Thu May 25, 2006 8:56 am
by Diana Kennedy
Thank you Novice! I will try this out. And come back with feedback!

PostPosted: Sat May 27, 2006 4:10 pm
by Diana Kennedy
Hi Novice and all,

Well I tried out around a bit. But it didn't work /wasn't the solution. It's my fault. My description of what I need was too general. So here's exactly what I would like to do:

We are still in the game I am working on, with the rider in the desert:

Image

In fact, the whole thing is the quest of the hero to get trough a lot of different challenges to free the sleeping beauty princess. (pretty classic, but I have a modern version in mind)

Anyway. You can't get to goal if you don't reach a certain final score. You don't even go to the next adventure, (level) when you fail the previous one. The first challenge is the ride trough the desert of the flying monsters. You must help the hero to get trough by shooting the flying demons with mouse clicking in them (pretty tricky, those little bastards are fast) When you shot one, you increase the score. But if a monster hits the rider (collision) it decreases the score.

I want the actual score being visible on the screen.

For nowI worked with the score as a text actor and with

Code: Select all
score.textNumber = score.textNumber + 20;


To increase the score when a monster is killed and with

Code: Select all
score.textNumber = score.textNumber - 20;


When a monster hits the hero.

So far so good. I plan to create a timer with the beginning of the desert ride for, let's say 2 or 3 minutes. When time is over, it is decided wether you were sucessful or not. If a minimum of score is not reached (let's say 400) an actor is created that creates a "game over" panel. "Sorry, try again".

If you have 400 or more score, the actor creates the next challenge. The ride trough the ghost swamp.

So the thing for me is now how to make it that the "end of chanllenge, now let's decide which way to go"-actor can use he score number to decide which actor will be created; The game over panel or the next level originator.

PostPosted: Sat May 27, 2006 4:26 pm
by Novice
Try something like this on your timer event
Code: Select all
if (score.textNumber>=400) LoadGame("Swamp Adventure");
else if (score.textNumber<400) CreateActor("Game Over"...);

PostPosted: Sun May 28, 2006 3:10 am
by Diana Kennedy
Woops! It gives me the following:

Image :shock:

PostPosted: Sun May 28, 2006 4:19 am
by Just4Fun
Hi Diana,

I think that your problem is coming from using the wrong number of arguments in the create actor function. Use GE's automatic CreateActor function in the script editor and it should automatically use the correct number of arguments. Just change the arguments that you need for your game. The following code should work:

if (score.textNumber>=400)
LoadGame("swampintro");

else if (score.textNumber<400)
CreateActor("gameover", "icon", "no parent", "no path", 0, 0, false);

PostPosted: Sun May 28, 2006 2:06 pm
by Diana Kennedy
Will try this out!รจ Just one thing: You both used a loadGame : But I don't work with loadgame (I want to have all things in ONE file). So in both cases an actor is created.

What is the "icon" thing?

I'll try this:

Code: Select all
if (score.textNumber>=400)
CreateActor("swampintro", "icon", "no parent", "no path", 0, 0, false);

else if (score.textNumber<400)
CreateActor("gameover", "icon", "no parent", "no path", 0, 0, false);

PostPosted: Sun May 28, 2006 5:05 pm
by Novice
Sorry bout that, i used part pseudo code you see i used
Code: Select all
CreateActor("Game Over"...);
notice the three dots that stand for etc. :wink:
You should use
Code: Select all
 CreateActor("gameover", "icon", "no parent", "no path", 0, 0, false);
type of code like J4f said.
I used Load Game function because i presumed that you keep your levels separate, but it's just an example the only thing that matters in my previous post is the if statement.
I hope i didnt give you too much trouble :wink:
Btw. the "icon" thing is the standard Pac-Man animation.

PostPosted: Sun May 28, 2006 5:43 pm
by Just4Fun
Hi Diana,

This is a little more explanation on using the CreateActor () function in GE. It comes from the Help docs that are included with GE's scripting section. I thought it might help you to better understand the arguments.


CreateActor: Creates a new Actor via script.

Actor* CreateActor(char *creatorName, char *animationName, char *parentName, char *pathName, int xpos, int ypos, int absolutePosition)

--> creatorName: any legal Actor name.
--> animationName: the animation valid for the Actor Name or "no animation".
--> parentName: any Actor name (including"Event Actor", "Collide Actor", "--> Parent Actor", "Creator Actor" and "no parent").
--> pathName: any path name (including "no path" and "random path").
--> x,y: the new Actor's initial position.
--> absolutePosition: true or false.
--> Return Actor if success, invalid Actor (with cloneindex = -1 and name = "") on error.


Script Editor Syntax:
CreateActor("GamePaddle", "Paddle_Animation", "no parent", "no path", 0, 0, false);


Novice is using the if() statement to help you make decisions in your script. So, if some condition is true then do this. Else if some other condition is true do it. You can place any sort of code under your if() decision. It could be any of GE's functions like 'CreateActor','DestroyActor', 'loadGame', etc.

For example:
( Note: in 'C' programming, you need the curly brackets {}when you use more than one statement in an if() decision)

if( score >=10)
{
CreateTimer("Event Actor", "MyTimer", 2000);
DestroyActor("Ball");
LoadGame("Level1.ged");
}
else if (score <10)
score.textNumber= score;


HTHs

PostPosted: Mon May 29, 2006 1:14 am
by Diana Kennedy
Thank you Novice and Just4fun.

No, Novice you did not gave me trouble. It's me that is simply too stupid. Always talk about scripting to me as if you were talking to a 2 year old kid ;)


Well, I used now this:

Code: Select all
if (score.textNumber>=120)
CreateActor("swampintro", "introswamp", "no parent", "no path", 0, 0, false);

else if (score.textNumber<120)
CreateActor("gameover", "gameover", "no parent", "no path", 0, 0, false);


It worked, but for some reason the actor was displayed half out of the view. Of course, I have the thing that during the gamei the view follows the rider (which is his parent) so I added

Code: Select all
view. x = -360;
view.y = -160;


in the timer event to bring back the view to the position where the actors gameover or swampintro shall load. It does so, but no actor at all is shown. Just black space.... :?

PostPosted: Mon May 29, 2006 1:50 am
by Diana Kennedy
Here is how it looks:

Image

As I said, the altering of the actors to display based on the score works fine, but the actors are not displayed correctly. Even if I write the position in the string (instead of 0, 0 ) it diesn't work, and when I move the view to the initial position (to where the actrs are,) then it shows just black space (and the other actors that are there)

PostPosted: Mon May 29, 2006 5:02 pm
by Diana Kennedy
I try and I try and I find no solution. Isn't there any idea? *big begging eyes*

PostPosted: Mon May 29, 2006 8:19 pm
by Novice
You should palce the coordinates of your backgroung actor instead of 0,0 in
Code: Select all
CreateActor("swampintro", "introswamp", "no parent", "no path", 0, 0, false);

so it should be
Code: Select all
CreateActor("swampintro", "introswamp", "no parent", "no path", 320, 240, false);

or something like it depending on your resolution. Play around with the numbers to center it.

PostPosted: Mon May 29, 2006 9:54 pm
by Diana Kennedy
Well I tried. But no matter what coordinates I put in, the actor is ALWAYS stuck in the upper-left of the screen!ImageImage