In State Duration - anylogic

How can I estimate the duration an agent stays in a specific state in a state chart?
I want to count the number of times an agent enters a state and the duration before the transition us triggered to the other state

Easiest way:
create a variable timerState of type double.
On entry of the state: timerState=time();
On Exit of the state: double timeInState = time()-timerState;
Then do what you want with that timeInState value.
Be VERY careful with this, though. You should not use the timerState variable for anything else.

Related

I'm Making Health Reduce Consecutively While Interacting With An Object, But It Only Reduces Once You Touch The Object

I'm trying to make health reduce while interacting with an object. I'm using Unreal Engine Blueprint. I want it so as soon as you interact with the object your health goes down, but once you stop interacting your health stops reducing.
Here's my blueprint:
I would do this in three parts:
On begin overlap, cast the overlapping object to the player pawn and if the cast succeeds, stash the player pawn in a member variable.
Run a repeating timer that deals damage every x seconds to the pawn stashed in the member variable if it's not null.
On end overlap, set the member variable to null.
This way if something other than the player comes in contact with the object, it's ignored, but when the player makes contact it starts repeatedly dealing damage until the player ends contact.
make private bool variable in the class.
set it to true when begin overlap.
set it to false when end overlap.
in Tick function reduce health when variable is true.
to be very simple...
fallow cpp way and make changes as in Tick function like the person above said ...
make private bool variable in the class. set it to true when begin
overlap. set it to false when end overlap.
in Tick function reduce health when variable is true.

Change value of slider without notifying listener

I am creating a GUI with GUIDE and have added a slider to my GUI. Afterwards, I have added a listener to my slider
myListener = addlistener(handles.mySlider,'Value','PostSet',#(src,evnt)myCallback(src,evnt, handles.figure1));
In the function myCallback I do some changes to an object I plot on an axis. I also made this object selectable such that another callback is called once the user clicks on the object. I would now like to initialize the slider with the appropriate value for the object just having been selected, but without calling the function myCallback.
That is, I need something like
setWithoutCallingListener(handles.mySlider, ValueOfSelectedObject);
Is that possible?
The easiest way to temporarily deactivate a listener is by adding a flag to the handles structure.
For example, at the beginning of your initialization routine, you set handles.isInitializing=true; guidata(hObject,handles);,and add if handles.isInitializing, return; end to the beginning of the listener callbacks. Remember to set the flag to false at the end of the initialization routine.
Alternatively, don't use listeners, but instead have all UI-element callbacks call a function updateUI(handles) (in addition to potential input checking; for example you may want to ensure that the slider can only take on integer values) which takes care of (1) adjusting all interdependent values (e.g. if you have a slider and an edit text box that need to be synced), and of (2) spawning whatever process you need to update the plot. This has the advantage that the UI element callbacks do not fire if you modify the element via a function.

Label is not updating iphone

I have singleton class in which I declare an int and a NSTimer so both are globally accessible. I decrease int value using timer and display on label which declare at A class.
What happened is that it decreases and keeps updating int value on label but when user moves back to A class and then jump into it doesn't update value.
I have logged the int and the text value of label and both are working fine but does no update onto view.
Please help me and indicate me where I am doing wrong. If anyone does not understand I'll update question with code.

Boolean variable that evaluates whether or not the current view has disappeared?

I am using an NSTimer that runs down from 15 seconds in a multiple choice quiz app. The app has two possible outcomes. The time may run down to zero, and the incorrectAnswer view is shown, in which case the Timer is invalidated/stopped and the static integer for its time is reset back to 15 for the next question.
However, the other possible outcome is that an answer is selected before time runs down, in which case I use the method viewWillDisappear to trigger further action. My problem is that I cannot reset the static integer for time from this method, because it is declared in the method above. I tried declaring it in the .h file, but there are problems because the integer is static.
I want to know if there is a boolean expression that evaluates if the current view has disappeared, because this way I can keep everything in the same method and be able to reset the static integer for time.
First, if your timer variable local to the class, it doesn't have to be declared as static. Secondly, you have two opportunities to address your problem from the viewController: viewWillDisappear and viewDidDisappear. Lastly, if you need to know if a view property has changed, you can do it via a KVO method. The problem you'll run into is if the view has truly disappeared, the view object may be toast by the time you reference it. Without more info, there is no way to tell what problem you're truly having.
Also, once you invalidate a timer, you can no longer use it. You must create a new timer.

gtk_adjustment_value_changed method

what does gtk_adjustment_value_changed method signify.
Can i increment gtk_adjustment_value_changed value instead of value
Regards,
iSight
If you look at the documentation for gtk_adjustment_value_changed(), you will see that there is no value for you to increment. This method tells the GtkAdjustment object to emit a notification to any object that is listening to the value-changed signal. You shouldn't have to use it in a normal application.