Any explanation for this broken code? (SOLVED)

DELETED_117713

  • Posts: 771
This is a player held weapons spawning system



A few attributes are named weirdly, mostly because I key-smash to name them.

Translations:

-wesps =weapon number.

-dats = a cancellation boolean so when a held weapon is spawned, it stops any others from spawning.

-wep = A attribute to set player animations depending on weapon held.

So whenever the player presses E, it's supposed to check through the game's weapon library. If it finds one, the code is stopped on the current weapon number.  The "X has?" booleans checks if the player has the weapon.

If both the weapon number, and the weapon has boolean are true to it's  question input, it'll spawn a held weapon and stop until you press E again. But if no weapon is found, it's skipped.

The next time you press E,  it will repeat above until you get to the next weapon.

If none are found, it goes to none held, otherwise, it'll reset back to the first weapon.

« Last Edit: April 07, 2014, 07:00:02 pm by fillergames »

MadManAdam

  • Posts: 371
Can you explain exactly why it's broken?  What's it doing wrong that it's not doing or what are you expecting to happen but it isn't getting executed?  Is pressing E not working or what?  Does only own weapon spawn and not others, etc.?  Where are you setting rev has, tommy has, and launcher has?   One problem is you need some otherwise if statements after your first one that's wrapped in the if dats equal true block.

« Last Edit: April 02, 2014, 08:42:22 pm by MadManAdam »

DELETED_117713

  • Posts: 771
Can you explain exactly why it's broken?  What's it doing wrong that it's not doing or what are you expecting to happen but it isn't getting executed?  Is pressing E not working or what?  Does only own weapon spawn and not others, etc.?  Where are you setting rev has, tommy has, and launcher has?   One problem is you need some otherwise if statements after your first one that's wrapped in the if dats equal true block.

It fails to create new held weapon actors, or any at all.

I'm setting the X has attributes to the weapons on the ground, when the player grabs the weapon, it sets the boolean to true.

And I may change the code up to your suggestions, thank you!

ManManAdam

  • Posts: 50
Part of the problem might be your set wesp code to set wesp to wesp +1.  When E is pressed put a print statement in there to set what value wesp is returning.

ManManAdam

  • Posts: 50
You'll also need an always block to set the position of the weapon.  Right now the weapon would just be created on top of the actor in the center and then once the actor moves the weapon won't follow.  Disregard all of that if you have that code elsewhere.

gamegirlxl

  • Posts: 713
I think that you need to use "otherwise if" instead of plain "if".  It might be going through the first if, making the second one true, which makes a chain.

I'll also say that "obfuscating" the names of things is a bad habit to have because people can't read it as easily.  I'm trying to break my own habit of extreme abbreviation because it's probably not going to be worth saving a little space.

DELETED_117713

  • Posts: 771
I redid the entire code, thanks to a public domain inventory behaviour. I got the weapons swapping, but it doesn't swap back from the first after you have no weapon equipped.



Attribute names:

-Dats: A boolean to prevent you from switching weapons too fast

-Weapon spawn: A boolean to prevent multiple weapons being on-screen at once, when a held weapon actor is killed, the boolean is set to true.

-Wesps: Weapon slot.

I set wesps to -1 after you have no weapon selected because it adds one after all the checking is done, therefore, it resets back to zero.

The game doesn't spawn a weapon the 2nd cycle, it swaps to nothing and refuses to cycle at all.

Epic428

  • Posts: 1118
do you ever set "dats" to true again? if so, then there's more code not visible that would be helpful.

As I see it now, you can only swap to the first weapon and that's it, because I don't see "dats" ever going true again, you'l never swap beyond the first weapon.

edit: same thing goes for "weapon swap"
James Moore - Official Support & Documentation.
We cannot and will not respond to PM's asking questions. Please make a new thread in the forums if you have any questions, Thank you.
For better support and faster response times, please post your logs regarding any Stencyl related issues. Debug > Logs > Generate Logs

gamegirlxl

  • Posts: 713
What if you pretended that your hands were a weapon and treated it accordingly?  They would have their own slot or something.

DELETED_117713

  • Posts: 771
Found out the issue!

The weapon Spawn boolean gets bugged out after the first weapon cycle!