Help with seemingly erroneous syntax error

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Cogboy
Posts: 45
Joined: Wed Jan 19, 2005 3:45 pm

Help with seemingly erroneous syntax error

Post by Cogboy »

Hi, just installed cygwin and psp sdk the day before yesterday and been having some fun with oslib, but now i've come across an error that makes absolutely no sense as far as i can see.

Here is the error i get from cygwin:

Code: Select all

$ make kxploit
psp-gcc -I. -I/usr/local/pspdev/psp/sdk/include -G4 -Wall -02  -c -o main.o mai
n.c
main.c: In function 'p1CalcPos':
main.c:77: error: syntax error before 'else'
make: *** [main.o] Error 1
seems fairly simple no? Think again.

Code: Select all

#include <oslib/oslib.h>
#include <math.h>

PSP_MODULE_INFO&#40;"Sams Game", 0, 1, 1&#41;;
PSP_MAIN_THREAD_ATTR&#40;THREAD_ATTR_USER | THREAD_ATTR_VFPU&#41;;


OSL_IMAGE *player1;


void Keys&#40;&#41;;
void p1CalcPos&#40;&#41;;

int main&#40;&#41;
&#123;
	//Initialize the different parts of the library
	oslInit&#40;0&#41;;
	oslInitGfx&#40;OSL_PF_8888, 1&#41;;
	oslInitConsole&#40;&#41;;
	
	//load files
	player1 = oslLoadImageFile&#40;"player1.png", OSL_IN_RAM, OSL_PF_5551&#41;;

	//Configure the joypad
	oslSetKeyAutorepeatInit&#40;40&#41;;
	oslSetKeyAutorepeatInterval&#40;10&#41;;

	//Initialize variables
	player1->centerX = player1->sizeX / 2;		//Rotation center of player1s sprite
	player1->centerY = player1->sizeY / 2;
	player1->x = 240;							//Place player1 at the center of the screen
	player1->y = 136;

	//Main loop
	while &#40;!osl_quit&#41;
	&#123;
          oslStartDrawing&#40;&#41;;	//Display code
          Keys&#40;&#41;;
          oslClearScreen&#40;RGB&#40;0,0,0&#41;&#41;;	//Black screen
          oslSetBilinearFilter&#40;1&#41;;	//Smoothing
          p1CalcPos&#40;&#41;;
          oslDrawImage&#40;player1&#41;;	
          oslEndDrawing&#40;&#41;;	//End of display code
	      oslSyncFrame&#40;&#41;;	//Synchronization
	&#125;

	//Game terminated &#40;HOME -> quit&#41;
	oslEndGfx&#40;&#41;;
	oslQuit&#40;&#41;;
	return 0;
&#125;

void Keys&#40;&#41;
&#123;
 oslReadKeys&#40;&#41;;

 //buttons 
 if &#40;osl_keys->pressed.triangle&#41; oslSetBilinearFilter&#40;0&#41;;
 if &#40;osl_keys->held.L&#41; player1->angle -= 3; //make a rotation to player1
 if &#40;osl_keys->held.R&#41; player1->angle += 3;
 if &#40;osl_keys->pressed.start&#41; oslQuit&#40;&#41;; //exit the game
&#125;

void p1CalcPos&#40;&#41;
&#123;
     float pi = 3.141592;
     float thrust = 0.6;
     float decay = 0.98;
     int maxSpeed = 25;
     static int xSpeed = 0;
     static int ySpeed = 0;
     static int speed = 0;
     
 if &#40;osl_keys->held.cross&#41;
    xSpeed+=&#40;thrust*sin&#40;player1->angle*&#40;pi/180&#41;&#41;&#41;;
    ySpeed+=&#40;thrust*cos&#40;player1->angle*&#40;pi/180&#41;&#41;&#41;;
 else
     xSpeed *= decay;
     ySpeed *= decay;
     
 speed = sqrt&#40; &#40; xSpeed * xSpeed &#41; + &#40; ySpeed * ySpeed &#41; &#41;;
 
 if &#40;speed>maxSpeed&#41;
    xSpeed *= &#40; maxSpeed / speed &#41;;
    ySpeed *= &#40; maxSpeed / speed &#41;;
    
 player1->x -= xSpeed;
 player1->y -= ySpeed;
&#125;
And the makefile just in case its involved somewhere:

Code: Select all

TARGET = main
OBJS = main.o
YOURLIBS=

INCDIR =
CFLAGS = -G4 -Wall -O2
CXXFLAGS = $&#40;CFLAGS&#41; -fno-exceptions -fno-rtti
ASFLAGS = $&#40;CFLAGS&#41;

LIBDIR =
LDFLAGS =
STDLIBS= -losl -lpng -lz \
		-lpspsdk -lpspctrl -lpspumd -lpsprtc -lpsppower -lpspgu -lpspaudiolib -lpspaudio -lm
LIBS=$&#40;STDLIBS&#41;$&#40;YOURLIBS&#41;

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = Sams Game

PSPSDK=$&#40;shell psp-config --pspsdk-path&#41;
include $&#40;PSPSDK&#41;/lib/build.mak
If i comment out my p1CalcPos function it compiles and runs fine, displaying my nicely smoothed spaceship in the center of the screen and rotating with the triggers.
But i can't for the life of me figure out what the hell is causing this error.

this is the first time i have used C, and only the seccond game i have coded. The first one being a flash version of what i hope this will be eventually.

Basicly, i need all the help i can get.
Thanks in advance,

Cogboy.
"the sony PSP was built by god, to determine who on earth had the best skills to defeat the armies of satan" - Saint Peter.
weltall
Posts: 310
Joined: Fri Feb 20, 2004 1:56 am
Contact:

Post by weltall »

the compiler is correct there is a problem with your if/else

if (osl_keys->held.cross)
xSpeed+=(thrust*sin(player1->angle*(pi/180)));
ySpeed+=(thrust*cos(player1->angle*(pi/180)));
else
xSpeed *= decay;
ySpeed *= decay;

...

if (speed>maxSpeed)
xSpeed *= ( maxSpeed / speed );
ySpeed *= ( maxSpeed / speed );

if you don't put { } after the if statement you can't do two lines of code but only one so the compiler see this like this


if osl_keys->held.cross = 1 do this xSpeed+=(thrust*sin(player1->angle*(pi/180)));
then also if osl_keys->held.cross = 0 do this ySpeed+=(thrust*cos(player1->angle*(pi/180)));.
where is the if of this else?

so to make this compile and do what you want to do, you must modify these lines like this:

Code: Select all

 if &#40;osl_keys->held.cross&#41; &#123;
    xSpeed+=&#40;thrust*sin&#40;player1->angle*&#40;pi/180&#41;&#41;&#41;;
    ySpeed+=&#40;thrust*cos&#40;player1->angle*&#40;pi/180&#41;&#41;&#41;;
&#125; else &#123;
     xSpeed *= decay;
     ySpeed *= decay;
&#125;
...
 
 if &#40;speed>maxSpeed&#41; &#123;
    xSpeed *= &#40; maxSpeed / speed &#41;;
    ySpeed *= &#40; maxSpeed / speed &#41;;
&#125;
Cogboy
Posts: 45
Joined: Wed Jan 19, 2005 3:45 pm

Post by Cogboy »

Thanks, i knew it would be something simple. :P
I guess i am kinda diving in the deep end here but this new OldSchoolLibrary is helping a lot.
"the sony PSP was built by god, to determine who on earth had the best skills to defeat the armies of satan" - Saint Peter.
Post Reply