Detecting when an attribute changes - STILL NEED HELP PLEASE!
I know this topic has been brought up once before, but at the time there were no viable answers...
So I would like to find out the easiest way for an actor to detect when an attribute changes and then act on that change, eg. in a rule.
In the past to get around this I have stored the last attribute recorded in another attribute and then just updated it with the next last when the attribute changes. This is both inefficient, and when I want to act for example after 5 changes to the attribute, I think I would have to have 5 separate attributes and rules all connecting with each other to achieve this.
Are there any other workarounds?
Many thanks
Max
So I would like to find out the easiest way for an actor to detect when an attribute changes and then act on that change, eg. in a rule.
In the past to get around this I have stored the last attribute recorded in another attribute and then just updated it with the next last when the attribute changes. This is both inefficient, and when I want to act for example after 5 changes to the attribute, I think I would have to have 5 separate attributes and rules all connecting with each other to achieve this.
Are there any other workarounds?
Many thanks
Max
Best Answers
-
The_Gamesalad_Guru Posts: 9,922
Looking at what you've got there isn't going to be a magic bullet E=MC2 type equation. You're going to have to break the things you want into blocks with a control function. So an attribute the when say it's 4 it tells the other blocks how to react. So basically find the things you can group under a common functions and go from your main attribute and translate that to the execution function of the other blocks. So say for scale 4 could equal a 20% increase 5 could equal 25 et.. Then for your spawn rate 4 could equal -20 time and 5 could equal -25 et... So I hope you get my logic here. So you have to basically build a translation code for all the blocks that trigger based on the one attribute. -
tenrdrmer Posts: 9,934
Well number 3 you would probably just need a counter that tracks up to the 5th level number and reset it to 0 either when its achieved or failed
and number 4 sounds like a simple timer. unfortunately I don't remember if GS has re enabled the ability of the timer to change values on the fly. it was an option at one time but an update a while back killed it.
I agree with FBS though. there is not going to be a magic formula that does all of this for you. I'm not sure why you think having the code broken up into a bunch of rules is going to be inefficient. its very common to have rules built to cover all the possibilities you want to cover in your game.
Answers
@JagonApps
Hi Max, I think I understand what you're asking: basically, that's one use of the Constrain Attribute behaviour, which can constrain a certain attribute to another which will be updated constantly. THen that way, when the constrained attribute is used, for instance in a Rule like "When suchandsuch attribute is > ??" it'll use the most up-to-date attribute value there is. Did that make sense?
//EDITED//
Thanks for the reply!
Err..Yer I think so, sorry I didn't say it exactly right, so my idea was to keep the next attribute to be used stored until the attribute.value changes again, so this is what I came up with, but it is still both inefficient and I don't know how to work it to change after 5 changes in attribute, instead of just 1 as shown here.
1. When attribute.stored = 0 --> change to attribute.value (1)
-attribute.stored now=1
2. When attribute.value DOES NOT EQUAL attribute.stored --> NEW LEVEL (SO PERFORM ACTIONS)
-attribute.stored=1, attribute.value now=2
3. Change attribute.stored to attribute.value
-attribute.stored now=2
Any help would be very much appreciated!
Cheers
Max
Remember though the attributes have to be assigned first to your prototype of the instance actor. So an integer or text would work fine.
I dunno if that helps. Im still working on how to time different in game events based on other events but I'm at work right now. Ill try to think about it some more and maybe have a better answer later.
So I think what you are saying is to use timers and other different 'decide' like events to trigger my attribute changes? So what I need a specific way to achieve this with my situation: (trigger attribute changes after a certain amount of levels). My way by recording past levels is ok but seems inefficient and so would you have any specific ways of telling when a level attribute changes after a certain amount of times?
Thanks
Max
Might look like this in a rule:
Change Attribute .. game.levelcount
.. +1
One difference is simple enough, but when I have multiple changes, say something happens when the level has changed 5 times, it is harder.
Ideally I would like a solution which does not restrain me from using an attribute that changes with a set amount each time and that is pre-determined, like the +1 of a level, but instead a random real number, for example that cannot be predicted.
If you get that! No worries if you don't have any solutions, I certainly haven't thought of a good one that can be used with any non-pre determined change in attribute.
Max
Really? Sorry. I will explain it better, as so far I have just been trying to achieve one part of my overall desire, of which I am partially there:
I am looking to create a sliding-like scale of difficulty (with increasing difficulty) as my game progresses by changing attributes such as an actor's size which affects the difficulty.
-I would like this increase to be endless in possibility (ideally).
-I would ideally like a clever equation that can be easily edited and with minimal code..
-Here are the examples of the situations in which I want the difficulty to be changed, along with the best solutions I currently have to fix them:
1. Having an increasing number of enemies spawning in the scene, after every level has been completed.
eg. When level increased by 1 --> change game.minimum spawn time --> by -10
--I think that would work!
2. By changing the percentage size of the actor, so that it is relative to other attributes eg. size.width and size.height
eg. When level increased by 1 --> increase size of actor by 10%
--I think that would work!
3. A way of changing the increment, eg. an increase in 5 levels, rather than just 1.
eg. When level increased by 5 --> increase size of actor by 10%
--Don't have solution to above
4. A way of increasing an actor's position change
eg. Every (attribute multiplier?) secs --> change position to rand. (x,x)
--Don't have solution to above
And who marked it...?? :-?
My goodness, what a giant MYSTERY.
Cheers
Max