Page 1 of 2

stupid code is stupid please help

PostPosted: Wed Sep 07, 2011 1:01 am
by DBGames
if (win == 5) ;
{
(textNumber==1337);
}
else
{
(textNumber=textNumber);
}

ERROR NEED ; ON LINE 5!

my thoughts...no i dont and when i put one you say the same thing. please help this is annoying

Re: stupid code is stupid please help

PostPosted: Wed Sep 07, 2011 1:02 am
by skydereign
Don't have the semicolon after the if statement. Also textNumber==1137 won't set textNumber, though I assume this code isn't meant for anything, due to the textNumber=textNumber.
Code: Select all
if (win == 5)
{
    textNumber=1337;
}
else
{
    textNumber=textNumber;
}

Re: stupid code is stupid please help

PostPosted: Wed Sep 07, 2011 1:10 am
by DBGames
im actually having tons of trouble trying to get my pong game to realize when the score equals 10 to make a win message. it diregards the number and just displays the win. im so frusterated.

Re: stupid code is stupid please help

PostPosted: Wed Sep 07, 2011 1:27 am
by skydereign
How are you doing the score? If you increase score like this.
Code: Select all
score++;

Display it like this.
Code: Select all
textNumber=score;

Then this should work for displaying the win.
Code: Select all
if(score==10)
{
    // win
}

Re: stupid code is stupid please help

PostPosted: Wed Sep 07, 2011 1:36 am
by DBGames
when has score++ been something?
i have been using normal actors with set text as 0.
then to add i use
Code: Select all
him.textNumber= him.textNumber+1;

and when i try to call up the win i do
Code: Select all
if(him.textNumber == 10) {   blah;  }

im so bad at this lol thanks for helping. ill prolly find something else wrong soon though.. heh

Re: stupid code is stupid please help

PostPosted: Wed Sep 07, 2011 1:39 am
by DBGames
also how would score++ be able to track multiple scores? in my game i have 2 to track.

Re: stupid code is stupid please help

PostPosted: Wed Sep 07, 2011 2:13 am
by Jagmaster
Score is supposed to be a global variable. It really doesn't have to be called score. ++ makes it increase by one instead of +=1. This makes it easier to track a score.
To set up a variable, use the variable tab on the script editor. There are some tutorials around to show you how to do this if you need help.
On an event you can simply add score++; instead of textnumber=textnumber+1; but then the text actor would need to have texnumber=score in the draw actor script.
Then make an actor and put in draw actor if(score==10){ //create game over screen and destroy actor} Hope I explained this in a non-confusing way. :)

Re: stupid code is stupid please help

PostPosted: Wed Sep 07, 2011 2:21 am
by DBGames
yup i get it now, thanks, also do you know how to set the text of an actore trough an if statement. i think i need a variable for the but it dosnt work.

Re: stupid code is stupid please help

PostPosted: Wed Sep 07, 2011 2:50 am
by DBGames
Code: Select all
Label.text=P1W;

on the text actor
and on another actor
Code: Select all
if(P1==10)
{
    P1W="Player Wins";
}

but it is erroring and dosnt change the text.. i know theirs some special way to go about text changing but my var isnt working for some reason

Re: stupid code is stupid please help

PostPosted: Wed Sep 07, 2011 3:09 am
by Jagmaster
Ahh, text is a string variable. You need to use strcpy to assign a value to text.
You'll need to change the var from int to string.

Draw:
Code: Select all
strcpy(text, Label);



Code: Select all
if(P1==10)
{
strcpy(Label, "You win");//Don't forget the quotes!
}


That should work, though I haven't tested it yet. :P

Re: stupid code is stupid please help

PostPosted: Wed Sep 07, 2011 3:13 am
by DBGames
it cant convert struct to * char ill fiddle with this and see what happens, thanks for the help. i hope you get back to me on this one lol.

did you know that my var is P1M
and my actor is Label

Re: stupid code is stupid please help

PostPosted: Wed Sep 07, 2011 4:38 am
by skydereign
You need Label.text.
Code: Select all
if(P1==10)
{
    strcpy(Label.text, "You win");//Don't forget the quotes!
}

Re: stupid code is stupid please help

PostPosted: Wed Sep 07, 2011 5:21 am
by lcl
Anyway, I recommend using sprintf() for adding text to actor or doing anything with text.
Here is a tutorial: viewtopic.php?f=4&t=10424&p=71521&hilit=sprintf+tutorial#p71514
Not the top post (it's about strcpy();), but the one you will see when you click that link. :D

Re: stupid code is stupid please help

PostPosted: Wed Sep 07, 2011 5:28 am
by skydereign
A small correction to your tutorial. %d does not do doubles, %d is the same as %i (both only handle integers). You can use %lf for doubles (long float).

Re: stupid code is stupid please help

PostPosted: Wed Sep 07, 2011 7:29 am
by Hblade
@sky:
I had no idea about lf. Thanks

to the first post about the if and else:
Code: Select all
if (win==5) {
textNumber=1337; }

textNumber will already = textNumber so there is no need to put "textNumber=textnumber" also, I noticed you have 2 equal signs at the top. Also don't forget the semicolons ;D