stupid code is stupid please help

Post here your demos and examples with the source files.
Forum rules
Always post the games with a screenshot.
The file must have the ged and data files (complete game source)
Use the forum attachment to post the files.
It is always better to use the first post to put the game files

stupid code is stupid please help

Postby DBGames » Wed Sep 07, 2011 1:01 am

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
User avatar
DBGames
 
Posts: 113
Joined: Wed Jun 24, 2009 10:13 am
Location: Bismarck, North Dakota
Score: 8 Give a positive score

Re: stupid code is stupid please help

Postby skydereign » Wed Sep 07, 2011 1:02 am

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;
}
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: stupid code is stupid please help

Postby DBGames » Wed Sep 07, 2011 1:10 am

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.
User avatar
DBGames
 
Posts: 113
Joined: Wed Jun 24, 2009 10:13 am
Location: Bismarck, North Dakota
Score: 8 Give a positive score

Re: stupid code is stupid please help

Postby skydereign » Wed Sep 07, 2011 1:27 am

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
}
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: stupid code is stupid please help

Postby DBGames » Wed Sep 07, 2011 1:36 am

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
User avatar
DBGames
 
Posts: 113
Joined: Wed Jun 24, 2009 10:13 am
Location: Bismarck, North Dakota
Score: 8 Give a positive score

Re: stupid code is stupid please help

Postby DBGames » Wed Sep 07, 2011 1:39 am

also how would score++ be able to track multiple scores? in my game i have 2 to track.
User avatar
DBGames
 
Posts: 113
Joined: Wed Jun 24, 2009 10:13 am
Location: Bismarck, North Dakota
Score: 8 Give a positive score

Re: stupid code is stupid please help

Postby Jagmaster » Wed Sep 07, 2011 2:13 am

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. :)
User avatar
Jagmaster
 
Posts: 875
Joined: Sun May 08, 2011 4:14 pm
Location: Not where you think.
Score: 82 Give a positive score

Re: stupid code is stupid please help

Postby DBGames » Wed Sep 07, 2011 2:21 am

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.
User avatar
DBGames
 
Posts: 113
Joined: Wed Jun 24, 2009 10:13 am
Location: Bismarck, North Dakota
Score: 8 Give a positive score

Re: stupid code is stupid please help

Postby DBGames » Wed Sep 07, 2011 2:50 am

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
User avatar
DBGames
 
Posts: 113
Joined: Wed Jun 24, 2009 10:13 am
Location: Bismarck, North Dakota
Score: 8 Give a positive score

Re: stupid code is stupid please help

Postby Jagmaster » Wed Sep 07, 2011 3:09 am

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
User avatar
Jagmaster
 
Posts: 875
Joined: Sun May 08, 2011 4:14 pm
Location: Not where you think.
Score: 82 Give a positive score

Re: stupid code is stupid please help

Postby DBGames » Wed Sep 07, 2011 3:13 am

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
User avatar
DBGames
 
Posts: 113
Joined: Wed Jun 24, 2009 10:13 am
Location: Bismarck, North Dakota
Score: 8 Give a positive score

Re: stupid code is stupid please help

Postby skydereign » Wed Sep 07, 2011 4:38 am

You need Label.text.
Code: Select all
if(P1==10)
{
    strcpy(Label.text, "You win");//Don't forget the quotes!
}
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: stupid code is stupid please help

Postby lcl » Wed Sep 07, 2011 5:21 am

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
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: stupid code is stupid please help

Postby skydereign » Wed Sep 07, 2011 5:28 am

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).
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: stupid code is stupid please help

Postby Hblade » Wed Sep 07, 2011 7:29 am

@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
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Next

Return to Game Demos

Who is online

Users browsing this forum: No registered users and 1 guest

cron