Page 1 of 1

A problem with creating an actor using script.

PostPosted: Fri Oct 09, 2009 7:29 pm
by Garfield501
Hello,
I have a problem with creating an actor with a script.

When my "game" starts up, it shows to pics. No problem here.
Then it goes to the "main menu" of the game.

Here it is supposed to check if variable "Save_game_excists" is equal to 0 or 1.
And if it's 1, it is supposed to create the actor "Load_Game".
Here it goes wrong.
It create's the actor "Load_Game" anyway.
Even when I put this code before the If-Then part.
Code: Select all
Save_game_excists = 0;


This is the complete code I am using.
Code: Select all
view.x = 160;
view.y = -120;
CreateActor("Main_menu_pointer_left", "icon", "(none)", "(none)", 0, 0, false);
CreateActor("Main_menu_pointer_right", "icon", "(none)", "(none)", 0, 0, false);
CreateActor("Quit", "icon", "(none)", "(none)", 0, 0, false);
Main_menu_pointer_left.x = New_game.x - 40;
Main_menu_pointer_left.y = New_game.y;
Main_menu_pointer_right.x = New_game.x + 90;
Main_menu_pointer_right.y = New_game.y;
Quit.y = New_game.y + 68;
Quit.x = New_game.x + 20;
if (Save_game_excists == 1);
{
    CreateActor("Load_Game", "icon", "(none)", "(none)", 0, 0, false);
    Load_Game.y = New_game.y + 34;
    Load_Game.x = New_game.x - 3;
}



How can I make it work my way.
I want to create actor "Load_Game" only, when "Save_game_excists'' is equal to 1.


Thanks in advance,
Mark

Re: A problem with creating an actor using script.

PostPosted: Fri Oct 09, 2009 7:51 pm
by skydereign
Okay, the problem is after your if statement, you put a semicolon. The ; will end the if statement. So what you are doing is checking if the variable equals 1 do nothing. Then it has the create. Here is what it should be.

Code: Select all
view.x = 160;
view.y = -120;
CreateActor("Main_menu_pointer_left", "icon", "(none)", "(none)", 0, 0, false);
CreateActor("Main_menu_pointer_right", "icon", "(none)", "(none)", 0, 0, false);
CreateActor("Quit", "icon", "(none)", "(none)", 0, 0, false);
Main_menu_pointer_left.x = New_game.x - 40;
Main_menu_pointer_left.y = New_game.y;
Main_menu_pointer_right.x = New_game.x + 90;
Main_menu_pointer_right.y = New_game.y;
Quit.y = New_game.y + 68;
Quit.x = New_game.x + 20;
if (Save_game_excists == 1)
{
    CreateActor("Load_Game", "icon", "(none)", "(none)", 0, 0, false);
    Load_Game.y = New_game.y + 34;
    Load_Game.x = New_game.x - 3;
}

Re: A problem with creating an actor using script.

PostPosted: Fri Oct 09, 2009 7:53 pm
by Kalladdolf
Oh, you just beat me to it. One second too late.

Re: A problem with creating an actor using script.

PostPosted: Sat Oct 10, 2009 11:39 am
by Garfield501
Okay, thank you.

I really must learn where to put a ; and where not.

Re: A problem with creating an actor using script.

PostPosted: Sat Oct 10, 2009 7:50 pm
by MrJolteon
in the first code, you wrote exist wrong. Read 7 words from the arrow<-- that's how you write it lol

Re: A problem with creating an actor using script.

PostPosted: Sat Oct 10, 2009 7:58 pm
by Kalladdolf
That doesn't affect the code though and therefore doesn't have any relevance.

Re: A problem with creating an actor using script.

PostPosted: Sat Oct 10, 2009 7:59 pm
by MrJolteon
@kall I was just mentioning it.

Re: A problem with creating an actor using script.

PostPosted: Mon Oct 12, 2009 2:21 pm
by Hblade
In your if statments, be sure to have 2 = signs, for example
Code: Select all
if (var1 == 0)
{
code here
}

With 1 equal sign, it acts as if It's setting the variable rather then reading it.

Re: A problem with creating an actor using script.

PostPosted: Mon Oct 12, 2009 6:23 pm
by Garfield501
Yes, thank you all for the advice.
It's working fine now.