How do I switch between two modes/controls and back?

Just started using Construct 2? Post your questions here

Post » Sun Jul 03, 2016 9:38 pm

Hello all! So I'm experimenting and trying to code a scene where you control a side scrolling character and you're able to board and pilot a physics based space ship. I have decent side scroller controls and now I'm beginning to implement some space ship controls. I'm able to "switch" and control the space ship but I can't switch back. The "F" button is a context sensitive button/action so if you're near a switch, near you're ship, near another player, etc, the "F" button will engage some sort of gameplay element/function. In this case, I'm just boarding and unboarding a space ship, switching "characters" or control states, if you will. Hope this is a clear explanation for my question. How would I go about switching on the fly my two modes of play, ground and air?

In the final version, I'd want the player near the ship in order to "board" and control it. I'd like the player to only be able to disembark by a context sensitive action/landing animation when close enough to the ground. Right now though, I'd just like to switch back and forth between the ship and character, from where I left last either one. Here's my code and a gif. I'm new to construct 2. I tried having the space ship code in the same event sheet and a separate one, it makes not difference. Maybe I'm having trouble linking them? Should overall "controls" of any and all characters/vehicles/etc be under the same event sheet? I'm not sure my event sheet management is very good. Thanks for looking at my questions folks!

edit: Deleted my original question over at the main "How do I....? thread. My topic title had a very beginner sounding title compared to the others so thought it probably belonged here.

Image
Image
Image
B
30
S
15
G
22
Posts: 183
Reputation: 14,221

Post » Tue Jul 05, 2016 12:23 am

Ok, don't know what I did but I fixed it. Eventually it crashed though and now I'm not able to get the exact code back in there to make it work. I'd really appreciate any help or suggestions on how to approach this.

It was working as intended, I could switch back and forth and pick off from where I last left the character or vehicle but the crash killed all that. Here's some of what I did to get it working. I moved the "Context Action System" group outside of the "Ground Control" group. I also created an instance variable for the ship called "state" and number it "0". "0" means off/idle, "1" means activated/controlled. If the player presses F and the ships "state" = 1, basically control would return back to the ground character and set "state" = 0. I guess I did some other important things because I can't get the results again.

Here's the code. Right now it's broken, it just turns my ground character invisible but it's close to how the code was looking while working earlier. If I remove that bottom block of code, I'm able to switch to the ship again. Thanks!

Image
B
30
S
15
G
22
Posts: 183
Reputation: 14,221

Post » Tue Jul 05, 2016 10:25 pm

Your problem is simple let me explain


Image

Using an on keyboard command or any kind of input will trigger everything that has that particular input in your event sheet so pressing F will trigger all of your on keyboard F inputs so your first one triggers first making your second condition true before it runs because constructs order of operation is top-down your second F input will always be true

Good luck with your project if you need help feel free to contact me through private message and we can talk on Skype, email, or steam I can help with any questions you have.
B
12
S
8
G
3
Posts: 33
Reputation: 3,483

Post » Thu Jul 07, 2016 5:56 am

Thanks Brandon. I got it working! I really need to go through more of the online documentation. I found this https://www.scirra.com/tutorials/158/ve ... two-states and it really helped me see what I did wrong. Yeah, my order of operations were screwy! Thanks for pointing that out, it's really going to help me going forward. And thanks for your offer! I'll definitely message you!

I'm wondering, should the player character controls and space ship controls have their own separate event sheets or share one? Does it matter?

So the code is fixed...for now. The player can switch to the ship at any time. The ship can only land and switch back to the player when the "ShipLander"(a small box that tests if the ship is close enough to a solid surface to land) underneath it collides with tilemap. Now I guess I should modify the code so that it takes into consideration how close the player is the the ship. The player has to be close enough to perform a climbing animation to enter the ship. Also I guess this specific code should also include events that "pick up" and "drop off" the player around the game level. Anyway, here's the code for anyone who's curios and for future generations!

Image
B
30
S
15
G
22
Posts: 183
Reputation: 14,221

Post » Thu Jul 07, 2016 7:57 pm

so it's really up to you how you want to set up your code but if you going to have a game with many different vehicles I'd recommend setting up controls for each one individually if they all have different movement mechanics. You are definitely on the right track with your state system. There's a few ways of doing it that different people use.

Some people do all of their code for that vehicle under each state as a sub event http://puu.sh/pTM5Q/bfa7f69faa.png

I prefer using something similar to this http://puu.sh/pTMsX/bb451fbf65.png

And if you need something to happen when a state's gets activated just use http://puu.sh/pTNa5/2264f15539.png

Both ways work so it's really up to you and in both these examples you can have way more than just the movement code under your States and of course there a ton of ways to do this so find the one that works best for your project Good luck :D
B
12
S
8
G
3
Posts: 33
Reputation: 3,483


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 3 guests