How to make this work? (Attribute value)

ahiungahiung Member Posts: 36

image
I tried to use attribute for value in expression editor, it worked. However, when the value of the attribute started changing IN-GAME, the function still running the "old/first value" before it changed. any ideas how to solve this?

Comments

  • colandercolander Member Posts: 1,610

    It looks like you need a Change Attribute game.Random To random(1,?) the "?" is for however many options you have. Place it in your timer above the first rule.

  • ahiungahiung Member Posts: 36

    nonono, not that. That is my own created attribute for item which I want to use when number"Random" appear.

    Look at the ....
    every [self.timer][e] seconds

    and

    on the left I highlighted attribute "timer" with 2 value to make sure you understand what I mentioned.

    so, that Random stuff has nothing to do with this problem, sorry if that wasn't clear enough.

  • colandercolander Member Posts: 1,610

    Ok I think I understand you now. That will fire every 2 seconds unless you are changing the value somewhere. If you are changing it I will need to see that code, can you upload a screen shot?

  • ahiungahiung Member Posts: 36

    Explanation: this function shows a logic which every ball touches the ground will deduct 0.1 secs/value from attribute "game.Timer"
    *I used game.Timer here instead of self.timer because I originally used this one, I thought by using self.attribute will fix it but wont.
    image
    Explanation: The output of the code, and you realized something strange about the spawned ball, it should be more than 1 ball since the timer goes 0 (which should spawned a lot of balls on the screen).
    image

  • colandercolander Member Posts: 1,610

    Ok you rule is only firing once because it is never = or < than 0. You will need a switch to turn the rule on and off.

    You could do this by creating a new integer attribute call it something like iTimerSwitch and use it as a rule condition "When iTimerSwitch = 1". Once you have set your time in the rule use a Change Attribute to change it to 0 (Off) and in your spawn timer use another change attribute to reset it to 1 (On), or however it works best for your game. You just need a way to switch the rule on and off.

  • ahiungahiung Member Posts: 36

    I'm bit lost.
    So, I do this?
    when time -.01 secs
    it became 1.90 secs, I turn off.
    I turn it back on for 1.90 secs.
    when time -.01 secs again
    it became 1.80 secs, i turn it off again.
    and turn it back on for 1.80 secs.

    Is this what you mean? because I want the ball dropped more when the ball touches the ground. It started from "spawning every 2 secs", and if it's near 0.01 sec, it feels like rain.

  • colandercolander Member Posts: 1,610

    Your timer is fine this is to do with your rule not firing. Create a game level attribute iTimerSwitch or type integer.

    In your rules;

    Rule - When game.Time > 0, Add another condition "When iTimerSwitch = 1"

    Change Attribute "gameTimer To game.Timer - 0.1
    Add another Change Attribute iTimerSwitch To 0 (This switches the rule off. When it is change to 1 in the Spawn Ball timer the rule will be able to fire again)

    Spawn Ball (Timer)

    Rule
    Rule
    Below all the rules and everything else in the timer add Change Attribute iTimerSwitch To 1 (Now the rule above will fire again because the condition has changed)

    Hope this has made sense.

  • ahiungahiung Member Posts: 36

    image
    image

    Like this right? I thank you for make things right, tho I dont really like it, I mean there's no more simple way.

    Now it works. and there are some things I want to pin up here.
    1. I set timer change attribute for every 0.1 sec, change attribute game.iTimerSwitch to 1. (It makes it impossible going 0/ or off)
    2. I put "spawn ball or the spawn time" inside a rule when iTimerSwitch is 1. (only spawn when iTimerSwitch is 1, which is 99% of the time)

    Thank you again, @colander.

  • ahiungahiung Member Posts: 36

    image

    There you go, alot of ball for you, haha.
    btw, how to mark post as [Solved]?

  • colandercolander Member Posts: 1,610

    Re read what I said carefully.

    Spawn Ball (Timer) contains;

    Rule (Contains spawn actor)
    Rule (Contains I assume another spawn actor)
    Below all the rules and everything else in the Spawn Ball (Timer) add Change Attribute iTimerSwitch To 1 (Now the rule above will fire again because the condition has changed)

    In Spawn Ball which is a timer you have a number of rules I couldn't see how many but below them put the Change Attribute iTimerSwitch To 1

    You have created another timer and another rule there is no need to do this. Hope this clears it up.

  • ahiungahiung Member Posts: 36

    Nah, it doesnt work, it just stop spawning as soon as a ball touches the ground.

  • ahiungahiung Member Posts: 36

    I know why it doesn't work, but I dont feel like fixing that way.
    you see my "Spawner" image, under rule.

    When [All] condition are valid:
    Attribute game.iTimingSwitch = 1

    Spawn ball (Timer) -----every [game.Timer] secs

    Rule 1~10

    Change attribute game.iTimingSwitch to 1

    So, which one activate the iTimerSwitch first?
    Ball(which touch the ground) or Spawnball Timer? of course the ball. it will turn iTimerSwitch to 0, and Spawnball can't do anything bout it because they have to follow iTimerSwitch 1 method.

  • ahiungahiung Member Posts: 36

    but don't worry, because I know what you want me to do....like this below

    image

    1. I separate "Spawn ball" from rule [when.....iTimerSwitch = 1].
    2. I (+) att game.iTimerSwitch =1 in every spawn (1~10)
    3. under those spawns1-10(rules), I add change att itimerswitch to 1.

    compare to what I did...
    1. Add a timer set every 0.1 secs, change att itimerswitch to 1.

  • colandercolander Member Posts: 1,610

    It can be hard to figure out a way to switch a rule on and off that works for your game. In my third post I said "or however it works best for your game. You just need a way to switch the rule on and off."

    Your rule is only firing once because even though game.Timer is decremented by 0.1 the rule still evaluates it as greater than zero so as far as it is concerned nothing has changed. However if you add a switch condition you can then turn it off and when the switch is turned on again the rule now sees a change and will run again.

  • ahiungahiung Member Posts: 36

    guess what? I just tried from what I said about understanding your guide, it seems you forgot that SpawnBall(timer) is has to be turned OFF in order to proceed to the next spawn timing. So, yeah, we can't use that timer for turning it ON because it wont ever, change the value of [game.Timer]. :disappointed_relieved:

    So, adding a new timer is a wise move, I guess.

  • colandercolander Member Posts: 1,610

    I posted at the same time you did. Yes that's it but move the Change Attribute below all your spawn rules so it is the last thing the timer does. Things get lost in translation sometimes, glad you got it working.

Sign In or Register to comment.