Assuming two things:
1.- That there is no defined order for the Update() function execution and that If a specific order is needed, you can define it yourself with the script execution order as specified here, and here.
2.- That the gameobjects are not updated according to their hierarchy as explained here
Something I could not clear out from the documentation is if you do not set any order for the script execution, once this is set 'randomly' by unity, if this order remains unaltered through the execution of the game or if the update execution order may change in time.
If you do not specify anything, the order won't be consistent. If you want a specific script to execute before others you HAVE to use the script execution order or use an array has suggested in you linked post.
Related
When I create a ParametersVariation simulation, the main model does not run. All I see is the default UI with iterations completed and replication. My end goal (as with most people) is to have a model go through a certain number of replications, but nothing is even running. There is limited documentation available on this. Please advise.
This is how Parameters Variation is intended to work. If you're running 1000 runs and multiple replications with parallel runs, how can you see what's happening in Main in each?
Typically, the best way to benefit from such an experiment is to track the results of each run using elements from the Analysis palette or even better to export results to Excel or similar.
To be able to collect data, you need to write your code in Java actions fields with root. to access elements in main (or top-level agent).
Check the example below, where after each run a variable from main is added to a dataset in the Parameters Variation experiment. At the end of 100 runs for example, the dataset will have 100 values of the main variable, with 1 value for each run.
I'm working with code that uses a tumbling window of one day, and would like to send early results to a different DataStream on an hourly basis.
I understand that triggers are a way to go here, but don't really see how it would work.
The current code is as follows:
myStream
.keyBy(..)
.window(TumblingEventTimeWindows.of(Time.days(1)))
.aggregate(new MyAggregateFunction(), new MyProcessWindowFunction())
In my understanding, I should register a trigger, and then on its onEventTime method get a hold of a TriggerContext and I can send data to the labeled output from there. But how do I get the current state of MyAggregateFunction from there? Or would I need to my own computation here inside of onEventTime()?
Also, the documentation states that "By specifying a trigger using trigger() you are overwriting the default trigger of a WindowAssigner.". Would my one day window then still fire correctly, or do I need to trigger it somehow differently?
Another way of doing this is creating two different operators - one that windows by 1 hour, and another that windows by 1 day. Would triggers be a preferred approach to that?
Rather than using a custom Trigger, it would be simpler to have two layers of windowing, where the hourly results are further aggregated into daily results. Something like this:
hourlyResults = myStream
.keyBy(...)
.window(TumblingEventTimeWindows.of(Time.hours(1)))
.aggregate(new MyAggregateFunction(), new MyProcessWindowFunction())
dailyResults = hourlyResults
.keyBy(...)
.window(TumblingEventTimeWindows.of(Time.days(1)))
.aggregate(new MyAggregateFunction(), new MyProcessWindowFunction())
hourlyResults.addSink(...)
dailyResults.addSink(...)
Note that the result of a window is not a KeyedStream, so you will need to use keyBy again, unless you can arrange to leverage reinterpretAsKeyedStream (docs).
Normally when I get to more complex behavior like this, I use a KeyedProcessFunction. You can aggregate (and save in state) hourly and daily results, set timers as needed, and use a side output for the hourly results versus the regular output for the daily results.
There are quite a few questions here. I will try to ask all of them. First of all, if You specify Your own trigger using trigger() this means You are going to effectively override the default trigger and thus the window may not work the way it would by default. So, if You for example if You create the 1 day event time tumbling window, but override a trigger so that it fires for every 20th element, it will never fire based on event time.
Now, after Your custom trigger fires, the output from MyAggregateFunction will be passed to MyProcessWindowFunction, so It will work the same as for the default trigger, you don't need to access the MyAggregateFunction from inside the trigger.
Finally, while it may be technically possible to implement trigger to trigger partial results every hour, my personal opinion is that You should probably go with the two separate windows. While this solution may create a slightly larger overhead and may result in a larger state, it should be much clearer, easier to implement, and finally much more error resistant.
I have a number of columns, and I want to be able to have the user press the label for each column to sort the data alphabetically\numerically by that field.
I can already accomplish this rather easily, but not very efficiently. I could make one script for each column and set it to sort by that column, perhaps even creating a global variable to keep track of the direction. Instead, I'd like to reduce it to one script and pass a variable to the script based on what button\label was pressed.
So far I've found people saying you can change the color of each one and get the variable that way, but I don't want the category headers to be different colors. Yes, I could simply use a one-step process for each one, but no way to reverse it when they click it a second time. Any ideas?
You can pass a script parameter where you specify the script to be performed on the button. From there, you can specify what field to sort on and if you like, set global variables for how the fields were sorted (order and name) that you can use in conditional formatting to give visual feedback.
There are lots of techniques out there for this, but this is one I have used especially for arbitrarily large data sets where sorts should not be done on calculations.
I'm new to Unity5, and I'm trying to create a simple game.
By extending MonoBehaviour, I receive an Update() function. But I don't know how it works behind the scenes.
My question is, are the Update() functions serialized (called one after the other) or parallelized when many MonoBehaviours have their own Update functions.
For example, if I have two scripts with its own Update in each, would the Updates be called at the same time (parallelized) or are they called one after the other (serialized)?
If they are serialized, how do I determine the order?
By default, new MonoBehaviour scripts are executed in whatever order Unity compiles them into. They are not run at the same time, they run one after another.
If you want to specify the execution order, you can do so under:
Edit > Project Settings > Script Execution Order.
Further reading: Execution Order of Event Functions
I have a bunch of TSQL change scripts, all named appropriately in sequence.
I want to combine these into one big script with a few twists. I include a version number function in the script that I update for each script so that once change 1 is run it returns 1, once 2 is run it returns 2 and so on. This function remains in the database and always returns the version of the schema/database.
I want to wrap each change script with a few lines that prevent a script that has already been run from running again, likewise it should prevent a change script from running on a schema version that is too "low". This allows me to bunch all the change scripts into one, and only missing changescripts will be applied when it all runs.
This is all fine, but I cant find a way to make osql / Query Analyzer / Sql Server Studio skip the parts that have alreay been run.
GOTO won't work across batches (Scripts contain "GO")
IF BEGIN END won't work likewise because of GO
Update: To reiterate, I don't need help remembering the current version number, I need a way to skip parts of the script to prevent already applied updates from reapplying.
I have tried a number of methods:
I can wrap the batch in an db_executeSql statement or EXECUTE but this leads to scoping problems.
I can wrap each batch in a IF dbo.DB_VERSION()!=REQUIRED_VERSION THEN BEGIN .... END construct, but this is messy and makes handling errors difficult.
Encountering situations where the change should not be applied is expected and is not an exceptional situation. So simply RETURNing when not applicable is not Ok.
Any other suggestions?
You can keep the version number if a table, and use the function to check the value in the table and compare in an IF statement to the version of the change you wish to make.