Need help

Talk about making games.

Need help

Postby Rebenely » Sun Apr 07, 2013 1:20 am

I am trying to create my first game. It is a top down shooter with only keyboard controls. I am still far from finishing the game but I immediately have some problems. What I wanted to do but can't are:

First, I wanted my character to shoot in whatever direction it is facing. My problem is instead of shooting a single bullet (BAttk), it shoots in all direction that I wrote on the script editor. As if it doesn't check about the conditions that I put or all the conditions are true.

I want it to shoot depending upon its facing. But if you press down Right and Up at the same time, it doesn't even create bullets(BAttk), different from the other two combination directions.

I also wanted to use timer in order to have a cooldown for each attacks, but it doesn't work.

Second is respawn. For every time the character leaves the arena(collision finish), he will die but will respawn again after 3 seconds. But again I can't put the timer to work but he is respawning (I don't know if I made a correct method in doing timers).

-------

I am open for total change of codes or starting from scratch again.
Every help is really appreciated.
Attachments
ArenaTest.zip
(306.43 KiB) Downloaded 115 times
User avatar
Rebenely
 
Posts: 16
Joined: Fri Apr 05, 2013 1:13 pm
Score: 1 Give a positive score

Re: Need help

Postby skydereign » Sun Apr 07, 2013 3:24 am

Okay, two problems with your if statements. First, you need to use two equals signs to compare, not one.
Code: Select all
if(var=1) // this is wrong, all it does is set var equal to 1
{
    // and therefore this code will be run
}

if(var==1) // this is correct, as it returns true if var is equal to 1
{
    // this only runs when var is equal to 1
}

The other problem, don't put semicolons after an if statement. A semicolon will end the statement, therefore negating the entire point of the if statement.
Code: Select all
if(var==1); // this statement ended at the semicolon
{
    // this code will always be run, since there isn't an active if statement before it
}

if(var==1) // this is what you wanted
{
    // this only runs if var is equal to 1
}

Another thing you want to note though after you fix those, is you should just put the if(InArena==1) at the beginning, and put the rest of the if(facing==number) calls within the InArena check. There's no point in checking in multiple places if the variable won't change within the event.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Need help

Postby GEuser » Sun Apr 07, 2013 3:26 am

Hi rebenely. I'm not as experienced as other members here so I hope this helps a little.

TIMER & RESPAWN PARTS

There are 2 reasons the timer won't work:-

1. You created the timer under Character's Collision Finish Event. You've done the first stage for timer creation but you've missed out the second part, which is to actually add a timer event for this timer you've created (named: respawn), like so:

a) Right mouse click Character > Actor Control (make sure Character is selected) > Add > Timer > Respawn (periodic, 3000ms) > Add Action > Script Editor

b) This will bring up script editor for event: Character->Timer(respawn)
c) This is where you need to put your respawn code (positions for character and all)

2. Even if you do everything in 1, it still won't work right because the timer (respawn) belongs to Character so when you destroy the Character (collision finish event) the timer (respawn) dies with it and doesn't do the 3000ms but would immediately do the respawn as next code line after it, thus respawning your Character immediately upon destroy. In your current code (Collision Finish Event) it just creates the timer, ignores it (since no event atttached to timer) and does the respawn immediately.

So basically you need another separate actor to be responsible for the respawning (so timer won't be prematurely destroyed).

MOVEMENT & BULLET PARTS

3. Firstly, might be better to use one script for all of those movements. One way is use 'Anykey' for KEY DOWN EVENTS and detect which key is pressed using gE's GetKeyState like so:-

Code: Select all
char *key = GetKeyState();


Now 'key' holds whatever the key pressed was.

You can check for which key is pressed like so:-
Code: Select all
if(key[KEY_LEFT]) // check if key pressed was LEFT
{
// your code (e.g. x-=2; )
   
}


or for two keys, like so:-
Code: Select all
if(key[KEY_LEFT]&&key[KEY_UP])
{
// your code (e.g. x-=2; y-=2; )
   
}


4. For the bullet your 'If' statements are messed up. Have you considered using angle and directional velocity, search the forums for them or might find that doing the bullets under the above method (AnyKey) might work too (depends on how you code it).

There are other ways search the forum or check out gE's script reference: http://game-editor.com/docs/script_reference.htm

Sorry for the rushed response (getting very late). Hopefully, other members more experienced then me will be able to help you further.

I like the graphics you've used. Good luck and let us know how it goes with the game :)
GEuser
 
Posts: 204
Joined: Thu Jan 05, 2012 3:08 pm
Score: 19 Give a positive score

Re: Need help

Postby Rebenely » Sun Apr 07, 2013 12:25 pm

Thanks for the solution. I am really new in scripting, thank you for telling me those things. :D :D :D
User avatar
Rebenely
 
Posts: 16
Joined: Fri Apr 05, 2013 1:13 pm
Score: 1 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest