New to Construct

For questions about using Classic.

Post » Tue Apr 12, 2011 9:52 pm

You should use what they call a "state machine", which can be set up something like this:

Weapon (player's private variable, default) = "Bullet"

Pressed key D
Trigger once
- If Weapon = "Bullet"
-> Set Weapon = "Shotgun"
- If Weapon = "Shotgun"
-> Set Weapon = "Bullet"

Pressed key C
- If Weapon = "Bullet"
-> Shoot default gun
- If Weapon = "Shotgun"
-> Shoot shotgun

Might take a bit of tweaking to get it to do what you want, but something like that should work fine. :)
B
20
S
9
G
6
Posts: 607
Reputation: 6,112

Post » Tue Apr 12, 2011 11:23 pm

Dang, I've done just what you've said, but I'm doing something wrong. Even though all 3 choices are under the Trigger Once condition, it will simple go back to default. I've got it set like this and I know what's wrong, but I don't know how to fix it currently:

+ input: On player 1 pressed "Change Weapon"
+ System: Trigger once
+ System: player ('weapon') Equal to "bullet"
-> player: Set 'weapon' to "shotgun"
+ System: player ('weapon') Equal to "shotgun"
-> player: Set 'weapon' to "missile"
+ System: player ('weapon') Equal to "missile"
-> player: Set 'weapon' to "bullet"

It pretty much goes through each condition and sets them correctly...right back to bullet. How do I fix this?
B
2
G
1
Posts: 12
Reputation: 474

Post » Tue Apr 12, 2011 11:46 pm

Yeah, that can be a problem sometimes. The easiest thing to do that I can think of is to make another variable called "Change" or something and add it in like this:

+ input: On player 1 pressed "Change Weapon"
+ System: Trigger once
+ System: player ('weapon') Equal to "bullet"
+ player ('change') Equal to "0"
-> player: Set 'weapon' to "shotgun"
-> Set 'change' to 1
+ System: player ('weapon') Equal to "shotgun"
+ player ('change') Equal to "0"
-> player: Set 'weapon' to "missile"
-> Set 'change' to 1
+ System: player ('weapon') Equal to "missile"
+ player ('change') Equal to "0"
-> player: Set 'weapon' to "bullet"
-> Set 'change' to 1

And then set it back to zero. That limits it so that it can only pass through one of the conditions rather than all three.
B
20
S
9
G
6
Posts: 607
Reputation: 6,112

Post » Wed Apr 13, 2011 12:08 am

i think it would be simpler to just use numbers
[quote:3235mgqm]weapon = 0[/quote:3235mgqm]
you know for yourself, and in your comments which number corresponds to which weapon
[quote:3235mgqm]on player pressed Change Weapon
add 1 to player('weapon')

if player ('weapon') is greater than the highest number you have defined
player('weapon') = 0[/quote:3235mgqm]
so it'll loop around to the first weapon...much cleaner and easier to maintain. just two little events that won't change no matter how many weapons you add

I think just using numbers and comments is fine, you can copy paste a little comment chart or the relevant parts wherever you need it, like here's your comment block for the event that increments:
remember this is just a comment field that does nothing except let you read it and remember
[quote:3235mgqm]0=pistol
1=shotgun
2=chainsaw
3=friendship ray[/quote:3235mgqm]

then on the event where you have
if player('weapon')==1 or whatever
you can have a little comment that just says
[quote:3235mgqm]1=shotgun[/quote:3235mgqm]

if you're against comments like that for whatever
make a bunch of global variables
one called shotgun with the default 1
one called chainsaw with the default 2
etc
and just never change those variables, so they'll be constant

then your events won't need comments because they'll look like this:
[quote:3235mgqm]if player('weapon') == global('shotgun')[/quote:3235mgqm]
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Wed Apr 13, 2011 12:19 am

Yeahhh, numbers work too. :D I got myself into the habit of using text now that there's way too much stuff to remember by number, so that didn't even occur to me. My bad!
B
20
S
9
G
6
Posts: 607
Reputation: 6,112

Post » Wed Apr 13, 2011 1:11 am

Alright lucid, that worked like a charm. Check out my new Platform, complete with multiple weapons, great music, and fun platforming:

http://www.mediafire.com/?o0ye76bb2pvmn9e
B
2
G
1
Posts: 12
Reputation: 474

Post » Wed Apr 13, 2011 3:00 am

Alright, now what I'm trying to do is to take the Sprite images of the weapons and place them on another sprite. So pretty much, when I choose Missile, the Missile's image will show on a sprite telling me what I've got selected.

What I've done is set up a sprite I call "currentWeapon" that's blank. I then have:

+ player: Value 'weapon' Equal to 1

How would I go about making sure that sprite "currentWeapon" shows the proper image of what I'm wielding?
B
2
G
1
Posts: 12
Reputation: 474

Post » Wed Apr 13, 2011 3:43 am

(Hopefully I get this one right >.>)

With the "currentWeapon" sprite, you can have multiple frames, each one being a sprite of a different weapon, and set the animation speed to 0 so it'll never actually change frame on its own. Then you manually tell it which frame to go to based on the value of 'weapon', so if 1 means shotgun and the second frame of "currentWeapon" is the shotgun sprite, say this:

+ player: Value 'weapon' Equal to 1
-> currentWeapon: Set animation frame to 2

and so on and so forth.
B
20
S
9
G
6
Posts: 607
Reputation: 6,112

Post » Wed Apr 13, 2011 4:34 am

[quote="SullyTheStrange":2fgzzmua](Hopefully I get this one right >.>)

With the "currentWeapon" sprite, you can have multiple frames, each one being a sprite of a different weapon, and set the animation speed to 0 so it'll never actually change frame on its own. Then you manually tell it which frame to go to based on the value of 'weapon', so if 1 means shotgun and the second frame of "currentWeapon" is the shotgun sprite, say this:

+ player: Value 'weapon' Equal to 1
-> currentWeapon: Set animation frame to 2

and so on and so forth.[/quote:2fgzzmua]

Hey that works! I was trying to use the image manipulator. It has a "Copy to" and "Copy from" for Sprite objects, but it wasn't really working out. Your method works great.
B
2
G
1
Posts: 12
Reputation: 474

Post » Wed Apr 13, 2011 7:10 pm

Anyone have a fun idea to try to implement into my platformer? I'm thinking something like a wall jump or and RPG inventory system or powerups or something, but I'm kind of lost how to implement any of them.
B
2
G
1
Posts: 12
Reputation: 474

PreviousNext

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 1 guest