The Daily Click ::. Forums ::. Klik Coding Help ::. Switching Between Characters
 

Post Reply  Post Oekaki 
 

Posted By Message

Scott Handelman



Registered
  19/05/2004
Points
  117
12th July, 2004 at 00:37:38 -

Hey guys. What I'm trying to do seems extremely simple, but for some reason, the program is just not behaving. I am making a game in which you have two characters on the screen at one time, but you can only control one. If you want to switch to the other character, you press the Space bar, and the character you were is replaced by an object that looks exactly like your character, but does nothing...he just sits there and holds your place. Meanwhile, the object that was holding the place of your other character is replaced by the player controlled character. It seems pretty straightforward, right? Here's the relevant code (The two characters are Hansel and Gretel and the two placeholding objects are Hansel Passive and Gretel Passive...Hansel and Gretel Passive are placed by me somewhere onn the screen at the beginning of each level).

Start of Frame --> Destroy Gretel
+ Destroy Hansel Passive

# of Gretel Passive = 1
+ Upon Pressing the Space Bar --> Create Hansel Passive at (0,0) from Hansel
+ Create Gretel at (0,0) from Gretel Passive
+ Destroy Hansel
+ Destroy Gretel Passive

# of Hansel Passive = 1
+ Upon Pressing the Space Bar --> Create Gretel Passive at (0,0) from Gretel
+ Create Hansel at (0,0) from Hansel Passive
+ Destroy Gretel
+ Destroy Hansel Passive

There are a couple of collision rules to keep the characters in the screen, but really this is all I have so far. What am I doing wrong? I've tried switching the order of the IF clause of the last two rules to no avail. As it is now, Hansel and Gretel Passive are on the first level and when I press Space Bar, nothing happens at all.

 
n/a

Scott Handelman



Registered
  19/05/2004
Points
  117
12th July, 2004 at 00:43:30 -

UPDATE: I tried assigning different keys to switch between the two characters and this actually solves the problem completely. But this is not what I want to do...I just want one key that will switch between the two characters. Anyone know why my coding won't do this?

 
n/a

AndyUK

Mascot Maniac

Registered
  01/08/2002
Points
  14586

Game of the Week WinnerSecond GOTW AwardHas Donated, Thank You!VIP Member
12th July, 2004 at 08:31:52 -

i dont know about your coding but i did start on a game with two changable characters.

what you could do it make the characters' movement events in two seperate groups and close one group if the other is open

and you could use a flag to toggle the change

eg
upon pressing space toggle flag 0

flag 0 is on (activate hansel events+deativate gretel events)
flag 0 is off (activate gretel events + deactivate hansel events)

 
.

Kramy



Registered
  08/06/2002
Points
  1888
12th July, 2004 at 17:35:30 -

Events are ran in order. When you press space, you create the other objects. Event 2 is then true for every condition when processing comes to it, so it resets back to how it was before.

As Andyuk said, a better way is just to toggle a flag, then check if the flag is on or off for movement.

 
Kramy

Assault Andy

Administrator
I make other people create vaporware

Registered
  29/07/2002
Points
  5686

Game of the Week WinnerVIP Member360 OwnerGOTM JUNE - 2009 - WINNER!GOTM FEB - 2010 - WINNER!	I donated an open source project
13th July, 2004 at 03:31:11 -

Yes, so once the player changes it changes right back. You need some sort of timer, so that when you press space it starts counting down. Then only allow the player to be changed when the counter is 0.

 
Creator of Faerie Solitaire:
http://www.create-games.com/download.asp?id=7792
Also creator of ZDay20 and Dungeon Dash.
http://www.Jigxor.com
http://twitter.com/JigxorAndy

Cybermaze



Registered
  03/04/2003
Points
  853
13th July, 2004 at 05:50:41 -

Yeah, based on your explanation what happens is excactly what the others have allready stated. When you press the space bar it makes the "+Upon pressing space bar" event true. The events are checked in a fraction of a second so you simply cannot press and release the key fast enough . It is a classical error so dont feel stupid or anything. The result is of course that the character does change ... and then change back again .

The easiest solution is something along AndyUK's solution.

 
If you knew, I would have to kill you...

Scott Handelman



Registered
  19/05/2004
Points
  117
13th July, 2004 at 23:07:30 -

Thanks all.

I do have another related question, though. I'm working on using a toggled flag and just assigning one character as player 1 and one character as player 2 (but giving them the same controls) and then just ignoring player 1 or 2's controls depending on if the flag is on or not.

The only problem I've run into is that, in the Global Events editor, there is no spot for controlling Player 2. Anyone know why this is and/or how to fix it?

 
n/a

Radix

hot for teacher

Registered
  01/10/2003
Points
  3139

Has Donated, Thank You!VIP MemberGOTW WINNER CUP 1!GOTW WINNER CUP 2!GOTW WINNER CUP 3!GOTW WINNER CUP 4!
13th July, 2004 at 23:12:52 -

It should appear as soon as you give an object the 'controlled by player 2' status. It's hidden otherwise. Check that.

 
n/a

Scott Handelman



Registered
  19/05/2004
Points
  117
13th July, 2004 at 23:37:30 -

I still don't know what I'm doing wrong. I've assigned one character to player 1 and 1 character to player 2, but player 2 hasn't shown up yet. I gave the characters different movement keys just to test it out, but that didn't work either.

 
n/a
   

Post Reply



 



Advertisement

Worth A Click