How do I - Set up the system to update a value always

Get help using Construct 2

Post » Wed Jul 22, 2015 2:29 am

Is it possible to have the system "If this variable is EVER ALTERED in any way, update the text that states how much is truly in here"


Instead of me manually telling the system minus 10, or plus 8, every time something occurs that changes the variable....

Is there a way to possible have the system be perhaps something of a watch dog?


For now every time I do something that altars the value I make sure I also tell the system "hey by the way THIS is the true value".

Just didn't know if I was working hard when I could be working smart.

I think this might have something to do with "I should probably use a function" is what I'm guessing.
B
6
S
2
Posts: 60
Reputation: 1,242

Post » Wed Jul 22, 2015 4:17 am

You should be able to simply plug the value of the variable into the text object. Just do something like,

Every tick -> Set text to variable

Note you don't need the quotation marks when you set text to a variable, or else it'll just spell out the variable name.
B
52
S
24
G
18
Posts: 295
Reputation: 13,090

Post » Wed Jul 22, 2015 7:01 am

Ah thank you for your response. I guess it is that easy, but I have an interesting problem.

My issue is that I have multiple units spawning multiple.. lets say "sheep".

I have set to every tick, every time a unit produces a sheep, to add to the entire variable.

The issue with "every tick" is that, I can't seem to "every tick, calculate how many sheep you have IN TOTAL"

When I tried using every tick in the past, it would only calculate the sheep for the first unit with the lowest id first.

So I had to resort to "For every unit, add their sheep to the total value"

So now I had to run around and do, for every sheep loss, minus from the total value.


But I'll try and make a new capx and see if some thing is mucking up the "every tick - set variable of total sheep"
B
6
S
2
Posts: 60
Reputation: 1,242

Post » Wed Jul 22, 2015 8:55 am

If it's just the total number of sheep currently on the layout that you want to keep track of, then yes, you should just be able to assign the variable/text to Sheep.Count (where "Sheep" is replaced with the actual name of the object, of course) to give you the total. Wouldn't know why it's not working, unless some other event is mussing with the value.
B
52
S
24
G
18
Posts: 295
Reputation: 13,090

Post » Wed Jul 22, 2015 9:03 am

Yes, honestly, I'm not sure, but I would not be surprised if I accidentally jammed something and now it wont ever work until I figure it out...

But I could not get the system to count all my sheep per each ... oh. wait. You see. the issue is these sheep are not ON THE LAYOUT.

I have them "stored" in local variables is why. So maybe thats why it would not work? of course if they were on the layout visibly I have no doubt that this would work.

But my issue is, I'm trying to calculate a local variable that each individual unit has and I want them all updating to the same "total variable". But I had to rely on my janked weird rigging where I hand feed the code +1 and -1 here and there.

Oh and to be clear - I have no problem of setting the text to the variable, my issue is - I need the sum of all local variables to be added into a global variable, but I can't seem to find a way to automate this process, except by always adding "+1" to the global variable wherever I see fit.

I was hoping there was a "System, detect change in local variable, adjust as necessary".
B
6
S
2
Posts: 60
Reputation: 1,242

Post » Wed Jul 22, 2015 9:53 am

It would just been easier if you would post the actual capx with a precise explanation of where the issue is instead of "let's say I'm using sheep"...

With a precise issue and precise code that causes the issue it will be easier to give precise answers.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
292
S
115
G
96
Posts: 7,295
Reputation: 70,785

Post » Wed Jul 22, 2015 10:20 am

Kyatric wrote:It would just been easier if you would post the actual capx with a precise explanation of where the issue is instead of "let's say I'm using sheep"...

With a precise issue and precise code that causes the issue it will be easier to give precise answers.


Thanks for the response.

I was more hoping for a "yes this is completely possible, check your code" or a "that is not possible". By the sounds of things it seems that yes, this should be completely possible.

I'll try and recreate the problem in a fresh capx and if the problem persists, will post said capx where someone will hopefully be kind enough to point out my error.

I would post the capx I'm working on now but its over 100 events and I'm afraid that my code is held together with duct tape, gum, and rubberbands, so "trimming it" scares me.

Thank you again, I'll try it in a new capx and will post my findings later.
B
6
S
2
Posts: 60
Reputation: 1,242

Post » Wed Jul 22, 2015 12:01 pm

Well according to your title and what I've understood from the first few posts, yes you can update a variable value according to an object count every tick.
But your previous to last post started to describe a situation I'm not sure to understand and that seems to depend on the code you are using itself.

To make a hair-stretched analogy: Is a car engine supposed to ignite when you throw gazoline through its designed circuit, yes.
What does happen when you modify the circuit ? Well, it depends on the modification and the circuit itself, doesn't it ? :D

Hence why you'd get a more definite answer and precise help displaying precisely the issue with the code you used.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
292
S
115
G
96
Posts: 7,295
Reputation: 70,785

Post » Wed Jul 22, 2015 7:08 pm

Ok so lemme see if I'm understanding the situation correctly up til now... There are several objects with a variable, each one has a different (changing) value assigned to this variable, and you need the sum of all these individual values?

Perhaps this could be done with a For Each loop, though I probably wouldn't assign it to Every Tick anymore because it might slow down performance. So it could look something like this:

(Assume global variable is used for the total sum)
Every 5 sec -> set Global Variable to 0
[sub event] For each Object -> add object's variable to Global Variable

This should tally the variable of every individual object, and the global variable should be set to 0 to avoid stacking old values with new ones.
B
52
S
24
G
18
Posts: 295
Reputation: 13,090


Return to How do I....?

Who is online

Users browsing this forum: Microbex and 23 guests