Stuck in coding rules

BasGoodboyBasGoodboy Member, PRO Posts: 310
edited September 2013 in Working with GS (Mac)
Hey all, I know this is kind of a long story, but I would appreciate any help cause I'm stuck for days in this problem now and tried everything I could think of..

I have problems in 2 different scenes.
The problems in both scenes are alike.

When player in the main scene clicks on the 'train' button, it changes the scene to the 'training grounds', where an enemy actor spawns and randomly switches position, where you can hit him. After you got his life bar to 0, or if you die yourself, the scene gets switched automatically back to he main scene, where the player can start over again and hit the 'train' button again if desired. If the enemy mob is hit he will interpolate to red for 1 second and interpolate back to normal colors after.

The main problem is i want this enemy actor every time the player hits the train button on the main scene, to be spawned at the exact same position in the 'training grounds scene', in the middle of the screen. The enemy actor is black then and after a countdown of 3 seconds he will interpolate to normal colors and be fightable. After these 3 seconds the enemy actor will randomly spawn positions.

The way I set things up now, and I had this problem earlier on another scene also, everything works fine at the first time the player pushes the 'train' button.
After that tho, if the player is back to the main scene again after a 'training session' on the 'training grounds', and he hits 'train' again, things go tricky.

The enemy mob spawns, but on some way or another, the mob's random position rule, which i set to only go off after 3 seconds, goes off right away. The enemy actor sometimes doesn't appear in black too (interpolated rule), but in normal colors and sometimes in red-ish, probably because the last time the player did the 'training session' he hitted the enemy actor and this actor somehow reminds this and go red again.

My rules:


Main scene:
TRAIN BUTTON: If touched, change attribute 'enemymob' to '1'.
set 'lifemeter_enemy' to '100'
set 'lifemeter_hero' to '100'
change scene to 'training grounds'

Actors:
ENEMY ACTOR: if attribute 'enemymobspawn' is '1', spawn actor in scene (on perfected positions of course)
after 3 seconds, every 2 seconds, set position 'enemymob' to 'random(1,3)'
if attribute 'lifemeter_enemy' = '0', set attribute 'enemymobspawn' to '0'
if attribute 'enemymobspawn' is '0', destroy actor

DAGGER BUTTON: if enemymob is at position random1, and touch is pressed, set life.enemyactor to '-5'
SWORD BUTTON: if enemymob is at position random2, and touch is pressed, set life.enemyactor to '-5'
CROSSBOW BUTTON: if enemymob is at position random3, and touch is pressed, set life.enemyactor to '-5'


TRAINING SCENE:
In the training scene the meters get to 100, so that works
In the training scene the first time player enters, the enemy actor spawns up perfect on position and in size,
gets destroyed perfectly after lifemeter_hero gets to 0 etc. Only thing that doesnt work is the second, third or whatever extra time you get into this scene by pressing the train button on the main scene. The enemymob spawns, but doesn't await it's 3 seconds before randomly reposition every 2 seconds and does it right away and isnt black.

ps. i didnt include all the detailed rules like interpolating, cause this all works and it's extra info which might confuse you.

Please anyone help, really stuck here.

Best regards,


Goodboi Gamestudios | Monster Jumper now on the App Store

Comments

  • KevinCrossKevinCross London, UKMember Posts: 1,894
    On your training button add change attributes to reset everything that was changed in the previous fight, I.e. the enemies position, colour and size etc.

    Put that on your training button before it switches scenes.

    If those are all scene attributes that can't be accessed from your training button then put all the resets needed when the enemy is destroyed or the player is, before it kicks them back to the other scene.
  • BasGoodboyBasGoodboy Member, PRO Posts: 310
    Like in 'reset scene'??

    Could I just make a boolean reset scene

    and on the train button in the main scene make if touch change attribute scenereset to 1

    and on the training grounds scene make if scenereset = 1, reset scene?

    Goodboi Gamestudios | Monster Jumper now on the App Store

  • BasGoodboyBasGoodboy Member, PRO Posts: 310
    Even with a complete scene reset, the enemy actor will reset at the good position, but will interpolate out of black right away, instead of after the desired 4 seconds which he does the first time.

    Goodboi Gamestudios | Monster Jumper now on the App Store

  • KevinCrossKevinCross London, UKMember Posts: 1,894
    No not a scene reset, change attributes.

    From your post, you were basically saying that it was remembering things from the old battles, so that means you've got attributes still set from the old battles that needs setting back to normal/default with change attributes. And the best place to do this is either on the training button, or on the rule that sends the player back a scene when they've destroyed the enemy or they themselves were killed.
  • BasGoodboyBasGoodboy Member, PRO Posts: 310
    edited September 2013
    @KevinCross, I am kinda sure I did 'reset' the enemy at a numerous of ways, but all ways he keeps spawning randomly the second time player enters the training grounds.
    Also he is not black and interpoled to normal colors after 3 colors, also not after reset, the second time player enters the trainings grounds.

    I tried really everything, on numerous ways like i said, but i really dont understand how to do it.

    Even the reset scene, which also should reset the enemy, will not do.
    Even then the enemy will spawn right, on the right position, but the interpole is incorrect then (turns to normal colors right away and sometimes even still has the red color of the hit of a previous training game, which dissapears in a second then.

    Is it helpful if i put all codes here? (thats very much tho)

    Goodboi Gamestudios | Monster Jumper now on the App Store

  • KevinCrossKevinCross London, UKMember Posts: 1,894
    Screenshots of the affected behaviours/rules often help.
  • BasGoodboyBasGoodboy Member, PRO Posts: 310
    Okay, I will do tonight, I'm having dinner soon with some friends, after I will post em! Hopefully you can help mate.

    Goodboi Gamestudios | Monster Jumper now on the App Store

  • KevinCrossKevinCross London, UKMember Posts: 1,894
    I might not be online much this evening so may have to help tomorrow if no one else sees a problem with your screenshots before then.
  • BasGoodboyBasGoodboy Member, PRO Posts: 310
    Perfect mate. I will see whoever is first ^.^

    Goodboi Gamestudios | Monster Jumper now on the App Store

  • BasGoodboyBasGoodboy Member, PRO Posts: 310
    edited September 2013
    Ok.. here we go.. the complete rules of the 3 actors which have to do with eachother:

    Main scene:
    'Train'-button:
    image

    'Training grounds'-scene:
    'Enemy mob' actor:
    (There is a lot of detailed rules in this which doesnt have to do with the my bug, but it might have, you never know, the mob got a random spawn (1,3) rule, and all 3 rules are written on these screens too. So that's why so many rules.)
    image
    image
    image
    image
    image
    image
    image
    image
    image
    image
    image

    'Training grounds'-scene:
    'background' actor:
    image
    image


    Hope you guys can help me out.

    Goodboi Gamestudios | Monster Jumper now on the App Store

  • KevinCrossKevinCross London, UKMember Posts: 1,894
    I'm afraid I'm not seeing anything obvious in those screenshots. If the attributes in the first screen are the ones you're having trouble with then they should all trigger each time you spawn the enemy target.

    Are you definitely destroying the actor before you leave the scene and re-spawning a new one each time you go to the scene? Are there any possibilities where this might not be happening?
  • BasGoodboyBasGoodboy Member, PRO Posts: 310
    edited September 2013
    No, these possibilities are not there :S.

    After a fight in the training grounds, i switch all attributes off before going back to the main scene. The enemy mob gets destroyed before switching back to the main scene.

    In the train button, if pressed, I switch all attributes on, before going tot the training scene, and the enemy mob gets spawned in a certain direction.

    I really have the feeling this is a bug of GS, I won't say this quick, but i have the same troubles in an other scene, where a sort of duckhunt-ish ' hunting ground' is.

    The ducks fly from one position to another, when touched there moving direction changes to down untill they are off screen, then they are destroyed. But after 10 seconds, when the hunting time is over and player gets kicked back to mainscreen and player clicks 'hunt' again, the last killed ducks are still in screen falling down, while they should be destroyed. It's actually the same problem as in the training grounds, where the enemy mob is still doing actions of the previous time player has been there, while it is definately destroyed and respawned.

    Goodboi Gamestudios | Monster Jumper now on the App Store

  • KevinCrossKevinCross London, UKMember Posts: 1,894

    The ducks fly from one position to another, when touched there moving direction changes to down untill they are off screen, then they are destroyed. But after 10 seconds, when the hunting time is over and player gets kicked back to mainscreen and player clicks 'hunt' again, the last killed ducks are still in screen falling down, while they should be destroyed. It's actually the same problem as in the training grounds, where the enemy mob is still doing actions of the previous time player has been there, while it is definately destroyed and respawned.
    This honestly sounds like a scripting error and not a bug but if you think it is a bug send your file to the support team and explain the problem.

  • KevinCrossKevinCross London, UKMember Posts: 1,894
    Perhaps also try and make your mini game like the duck hunt one outside of your main project to see if working in a new file helps find the problem. You don't need to load it with graphics and sounds. Just basic squares for your ducks and some basic rules to move and kill them.

    Being in a new file without all of the noise from the rest of your game in it might even help find a better way to do it

    Do the same with the enemy training ground. Create a really basic version with a couple of attributes.
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    edited September 2013
    One thing I noticed before is you're always using touch is pressed for resetting. This means the code will only execute as long as it stays pressed for reset rules use touch is released. Touch is pressed is momentary. Touch is released is like flipping a switch it stays on. Always make sure you put your change scenes in a .1 second timer if you have other code firing before it. It takes time for these things to execute. Just because it works most of the time doesn't mean it's right. Never have any code in a rule after the change scene behavior. Code executes in order. Watch my video on code order. Save yourself a lot of frustration and take sometime to learn how to properly structure your code. I can clearly see you don't understand how code fires and executes in GS. Learn hove rules function and when and how the fire based on the conditions. Learn how to properly order your code et.. This will cut down on the frustration.
  • BasGoodboyBasGoodboy Member, PRO Posts: 310
    @KevinCross good tip mate, I'm actually doing that right now. I think indeed a bug is not the problem, it must be my coding order or something.
    @FryingBaconStudios those are some very good tips. I tought I did all the rules before the change scene rule, but I'm gonna doublecheck and the touch is released tip is perfect! I checked out your videos before but never saw a code order video of you but will recheck. Thanks!

    Goodboi Gamestudios | Monster Jumper now on the App Store

  • BasGoodboyBasGoodboy Member, PRO Posts: 310
    @FryingBaconStudios you gave me the ultimate tip. Apparently it had to do with the 0.1 second timers before entering the scene, and before closing the scene.

    My training grounds are working perfect now ^.^, so the rest should do too.

    Goodboi Gamestudios | Monster Jumper now on the App Store

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    edited September 2013
    Yep I do this for all my change scenes if I have other stuff that needs to fire just before the scene change. Giving the device that extra tenth of a second is key. One code cycle takes .03 of a second so .1 is the perfect cushion to account for any lag. Look at the first screenshot there is a change attribute after the scene behavior.
  • BasGoodboyBasGoodboy Member, PRO Posts: 310
    Yeah that attribute is still after the change scene, because it's the attribute that destroys the button. If i set it before the change scene, the button gets destroyed before changing scene, which is not good ofcourse.

    That rule IS working by the way, altho it's behind the change scene rule.

    Goodboi Gamestudios | Monster Jumper now on the App Store

Sign In or Register to comment.