Local variables or variable scoping
I needed to drive a timeline based animation at a variable speed based on the rotation using an imp of a wheel. I achieved this by using the angular velocity of the wheel as the operand for the + operator in a variable modifier. Then the variable value is wired to the playhead. That worked great but the variable is global so I couldn't then clone this contraption elsewhere in the scene.
So my question is, is there another way to do something like this, or might we get a way to scope variables in future? Bear in mind, a counter wouldn't work (i assume) since I need a float value.
Update, if anyone is interested: I couldn't replace the flag variables with switches, so I used a selector instead. In theory, I could probably just use nodes. Does one selector take up less logic than three nodes?
I couldn't replace the scale variable with a slider either, as it's difficult to increment the slider so I used a counter instead. I need to be able to jump the counter around though - so I need to figure out how to do that...
I think I might be able to solve my problem with switches and sliders. I wasn't expecting them to be in input so I couldn't find them before. I'll try when I get home tonight...
I also have this problem - I am trying to make a capture point (like from the original star wars battlefront), so I need three variables. The first one will be a variable between -1 and 1 to say what the balance is, the other two are essentially just flags to say this is controlled by the blue team, or this is controlled by the red team.
That's three variables and I think 10 variable manipulators. I dont want to rename them all for my second capture point!
I tried using the exclusive gate for the flags, but I cant switch it on and off in the same way as setting variables, and the other one still needs to be a scale...
I'm not sure that this is is right for what you need but I've just published a contraption which gives an id to each object emitted.
The instance can then compare it's id to a variable and trigger some logic, for example to change an "active" character.
It's called "Emitted Instance Identifier"
It would be really useful to be able to scope variables to specific chips etc
At the minute I've got an emitter which outputs objects, and have found a way to locally scope a "variable" using a selector to save state after being emitted but I'm limited to only creating 9 instances. Going to try the calculator method now..
So it seems like you can manipulate a value slider's value using logic. https://indreams.me/element/b2j9Fm3nVTs
I guess that's the easiest answer.
Peter, I'll try the timer idea as well as the calculator one. Thanks again.
@Nurbldoff Yeah I like the idea of wiring directly into a variable so it doesn't have to be named. Or perhaps they could be scoped to the current microchip and its children. I guess variables were originally intended for sharing values between scenes, not for this sort of thing but in this case at least they turned out to be very useful. All sorts of logic gets really tricky quickly if you don't have some way of maintaining state easily.
Regarding conflicts between different creators stuff, I hand't considered that. There should be at least a uniqueness convention for naming.
I think somehow scoping variables is a must, unless I'm missing a way to do that.
Having all variables global will lead to many confusing bugs once people start using each other's logic contraptions as "black boxes". Any variable changers can potentially affect variables anywhere. Especially since the slow text input don't encourage long, descriptive variable names, I think we'll see a lot of e.g. "value" or "result" variables. Just using a variable changer in a microchip and then cloning the chip can make both clones broken (this happened to me, and it took me while to figure out what was going on).
Any particular reason it's not possible (AFAIK) to directly wire a changer to variables, instead of using the name? I think that would solve most of the issues.
I suppose it's possible to avoid using variables most of the time, but since they're there, they will be (ab)used :)
Also try the rotational velocity into a timer set to speed (I think it’s speed) and then wire that into the playhead. That should rewind when no power is coming from the rotation sensor.
Sounds like a really cool contraption. :)
Thanks Peter. I actually tried that first but it wouldn't play backwards. I may be wrong but I believe playback speed only accepts a positive value?
In my contraption you can kind of scrub the animation back and forth by spinning the wheel either way.
I considered what other gadget might act as a way to hold a value that can be incremented or decremented, e.g. the value slider, but that can't be manipulated in this way.
I just had an idea actually that I will try later. What about a + calculator gadget whose output is wired back into operand A? Then my velocity goes into operand B. You should get an infinite loop where the value gets incremented or decremented based on that 2nd operand.
Cool idea. It might be simpler to wire the angular velocity straight into the playback speed of the timeline. You may need to go through a signal manipulator first to get the animation speed you want.
Anyway, this bipasses the global variable so you can duplicate your contraption else where in the scene.
Hope this helps :) Peter