Unexpected declaration

Non-platform specific questions.

Unexpected declaration

Postby edh » Sun Mar 02, 2008 8:52 pm

I have a global integer called "canKick"

In my drawActor, I have the following
Code: Select all
if (canKick == 1)
    {
        if (rand(10) <= 1)
            {
                canKick = 0;
                Actor* ball = CreateActor("ball", "rolling", "(none)", "(none)", 0, 0, false);
                ball->yvelocity = 5 + rand(10);

            }
 
    }


When I try to save, I get "Error line 6: Unexpected declaration canKick"

If I ignore the error, I cannot enter Game Mode, it complains again about the script.

If I move canKick = 0, like this, there is no problem
Code: Select all
if (canKick == 1)
    {
        if (rand(10) <= 1)
            {
               
                Actor* ball = CreateActor("ball", "rolling", "(none)", "(none)", 0, 0, false);
                canKick = 0;
                ball->yvelocity = 5 + rand(10);

            }
 
    }


Looks like a parsing error in the script editor, maybe?
User avatar
edh
 
Posts: 233
Joined: Thu Sep 13, 2007 12:17 am
Location: Maine, USA
Score: 14 Give a positive score

Re: Unexpected declaration

Postby makslane » Sun Mar 02, 2008 9:02 pm

The problem is the Actor* ball declaration.
In C the creation of variables musst be the first declaration of a block.
Game Editor is an open source game creator software that's wants to pay it's developers to keep evolving.
If you like Game Editor, make a review!
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Re: Unexpected declaration

Postby edh » Sun Mar 02, 2008 9:13 pm

Doh! :oops:

Thanks Makslane, I forget about that.
User avatar
edh
 
Posts: 233
Joined: Thu Sep 13, 2007 12:17 am
Location: Maine, USA
Score: 14 Give a positive score

Re: Unexpected declaration

Postby Fuzzy » Thu Mar 06, 2008 5:54 am

I usually set my conditionals at the end of the block "canKick = 0;" so that its never activated until all my block has fired.

Which means I didnt know about that "gotcha". Its good to know! Thanks Makslane!
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Re: Unexpected declaration

Postby edh » Thu Mar 13, 2008 4:52 pm

I tried setting this conditional early to avoid a race. Occasionally, I end up with more than one kicked ball on the screen. Still.

I'm going to have to rethink this... :?
User avatar
edh
 
Posts: 233
Joined: Thu Sep 13, 2007 12:17 am
Location: Maine, USA
Score: 14 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron