Community
Message Board

Chat room - users
Game Over
( 394431 downloads)
Work In Progress
( 523201 downloads)
Links

Code Exchange
Downloads
Tutorials
Add to Favourites

Submit news

DIV ARENA FORUMS
Not logged in [Login - Register]
Go To Bottom

Printable Version  
Author: Subject: Help! End Expected
pommyman
DIV Junior
**




Posts: 10
Registered: 19-1-2017
Member Is Offline


[*] posted on 21-1-2017 at 12:08 PM
Help! End Expected


Hi. I'm trying to do a simple shooter type game, but have come across a very basic stumbling block. After doing my first bits of code and then trying to run it, I get an error "end expected". I thought all the begin/end pairs were correct. Can someone please check to see where I'm going wrong?
/*
* test1.PRG by Peter
* (c) 2017 Home
*/

PROGRAM test1;

BEGIN

load_fpg("test1.fpg");
spacecraft();

process spacecraft()

Begin
graph=1;
x=160;
y=100;

loop
if (key(_right))
x=x+1;
end
if (key(_left))
x-=1;
end
if (key(_down))
y+=1;
end
if(key(_up))
y-=1;
end

frame;
end
END
process shot(x,y)
begin
graph=3;
loop
y-=16;
frame;
end
end

END

Thanks,

Pommyman
View user's profile View All Posts By User
CicTec
DIV Pro
******




Posts: 471
Registered: 6-8-2016
Member Is Offline


[*] posted on 21-1-2017 at 12:16 PM


Hi pommyman,

You have missing END statement after "spacecraft();" to close the Begin of program:

Code:
PROGRAM test1; BEGIN load_fpg("test1.fpg"); spacecraft(); END ...

Now should compile. :)

[Edited on 21-1-2017 by CicTec]

[Edited on 21-1-2017 by CicTec]
View user's profile View All Posts By User
pommyman
DIV Junior
**




Posts: 10
Registered: 19-1-2017
Member Is Offline


[*] posted on 21-1-2017 at 12:18 PM


Hi.

Thanks, but I tried that and get an expecting process error when I do that.

Any more suggestions?

Cheers.
View user's profile View All Posts By User
CicTec
DIV Pro
******




Posts: 471
Registered: 6-8-2016
Member Is Offline


[*] posted on 21-1-2017 at 12:21 PM


Yes, you have also to delete the last END (process shot).

I suggest the use of indentation of the code, so it is easier to identify errors like this.

[Edited on 21-1-2017 by CicTec]
View user's profile View All Posts By User
pommyman
DIV Junior
**




Posts: 10
Registered: 19-1-2017
Member Is Offline


[*] posted on 21-1-2017 at 12:24 PM


You legend! That did it. Thanks for the quick replies.
On I go!
Cheers,

Pommyman
View user's profile View All Posts By User
MikeDX
DIV Nerd
*********


Avatar


Posts: 8388607
Registered: 25-2-2016
Member Is Offline


[*] posted on 21-1-2017 at 12:41 PM


Just came to reply and see cictec has helped you out.

Looking forward to seeing what you make pommyman!

View user's profile View All Posts By User
pommyman
DIV Junior
**




Posts: 10
Registered: 19-1-2017
Member Is Offline


[*] posted on 21-1-2017 at 12:54 PM


It all worked, and I've now got a ship that moves across the screen, enemies that approach from above, and I can fire bullets that destroys the enemies.
Next, to add scores, sound, collision if an enemy hits the ship and maybe an increasing difficulty as the game progresses.
View user's profile View All Posts By User
MikeDX
DIV Nerd
*********


Avatar


Posts: 8388607
Registered: 25-2-2016
Member Is Offline


[*] posted on 21-1-2017 at 01:49 PM


You might want to add something that "kills" the bullets as thry go off screen

View user's profile View All Posts By User
pommyman
DIV Junior
**




Posts: 10
Registered: 19-1-2017
Member Is Offline


[*] posted on 21-1-2017 at 03:40 PM


Hi Mike. Yeah, I added a bit of code that kills the process once they get to the top. It works OK too.

I also added a collision from the enemy to the player, but it happens almost instantly.

Is there a way I can add a pause at the start to get the player ready?

Cheers,
View user's profile View All Posts By User
CicTec
DIV Pro
******




Posts: 471
Registered: 6-8-2016
Member Is Offline


[*] posted on 21-1-2017 at 04:54 PM


Quote: Originally posted by pommyman  
You legend! That did it. Thanks for the quick replies.
On I go!
Cheers,

Pommyman

I'm happy to help. :)
View user's profile View All Posts By User
CicTec
DIV Pro
******




Posts: 471
Registered: 6-8-2016
Member Is Offline


[*] posted on 21-1-2017 at 04:55 PM


Quote: Originally posted by pommyman  

Is there a way I can add a pause at the start to get the player ready?

There are many ways to add a "pause", you could provide more details on what you mean by "pause", please?
View user's profile View All Posts By User
pommyman
DIV Junior
**




Posts: 10
Registered: 19-1-2017
Member Is Offline


[*] posted on 22-1-2017 at 07:23 AM


Something along the lines of "press a key to start", so that it give the player time to be ready before the enemy comes. Also a way to delay the enemy spawning for a few seconds once that key has been pressed.
Just something to add a little more "player friendly" touch.
Cheers,
View user's profile View All Posts By User
CicTec
DIV Pro
******




Posts: 471
Registered: 6-8-2016
Member Is Offline


[*] posted on 22-1-2017 at 11:00 AM



Well, there are many forms, one could be inserted before the game loop (the process that controls the game) another loop waiting for you to press a button, example:
Code:
// main loop loop // freezes all processes in the lot / level, this blocks the physical execution of the process code, but allows the rendering to screen. signal(TYPE enemy, s_freeze_tree); signal(TYPE player, s_freeze_tree); text_id = write(......, "Press a key to start"); // waiting loop while(scan_code == 0) frame; end // delete "key message" delete_text(text_id); // awakens all game processes to start the game / level signal(TYPE enemies, s_wakeup_tree); signal(TYPE playe, s_wakeup_tree); // level loop while(level_done == false || player_lives > 0) ... frame; end end

the code "while(scan_code == 0) frame; end". just check the pressure of a button, when this happens scan_code (global variable, see its use with F1), it contains the scan code of the last key pressed in the last frame:

the SIGNAL function sends a signal to a determined process, in this case "s_freeze_tree" indicates the function to freeze all processes of type "ENEMY / PLAYER" and each one of these processes in turn once freeze all those created (even of different types).

The "s_wakeup_tree" command performs the opposite operation, ie awaken or thaw processes.

The sentence FRAME is fundamental within the loop in order to finish properly and resume the execution of the current process and all others in the run queue, without it you would cause a runtime error.

[Edited on 22-1-2017 by CicTec]

[Edited on 22-1-2017 by CicTec]
View user's profile View All Posts By User

  Go To Top

Powered by XMB
XMB Forum Software © 2001-2012 The XMB Group
[Queries: 18]