In C-script, is the time symbol"t" treat as the system clock time or only S-cript block time

For example, If we have a if function to let the csript block generates y=sin(2pit) only during simulation time 0.3~0.5sec (Assume we have a simulation time for 1sec). In this 0.3~0.5 sec, the function will be generated. However, what is “t” in function represents, is it “0.3~0.5” or “0~0.2” (Since the C-script only runs for 0.2 sec).

Hello,

There is a macro “CurrentTime” built into the C-Script engine that you can call in your logic and will get the current simulation time, with respect to t=0. So, 0.3 to 0.5 seconds in your case.

Regards,

Kris

Hi, what if I want to use 0~0.2 instead of 0.3~0.5? Which is that I dont want to use the system clock, I want to use a independent C-script block which runs its own clock.

Would you be able to post a simple version of your model and script?

You could code a counter (if using fixed sample time) or integrator that would act as a “local clock” within the C-Script. For example, if you want to have a one-shot timer. Or you could reference simulation time, but use a time delay or store the time of the input event to calculate a time difference.