I am trying to use if statements to go to two different frames in the Director game project but eventhough I have go to frame 32 for one set and go to frame 31 for another, they are both going to the same frame 31. What am I doing wrong? I can't figure it out. (see the code example here:)
--
on timeOut
if the timer >= 360 and sprite(16).visible = 1 then
member ("tellIt").text = "TIME UP"
_movie.go(32)
end if
if the timer >= 360 and sprite(15).visible = 1 then
member ("tellIt").text = "TIME UP"
_movie.go(32)
end if
if the timer >= 360 and sprite(14).visible = 1 then
member ("tellIt").text = "TIME UP"
_movie.go(32)
end if
if the timer >= 360 and sprite(13).visible = 1 then
member ("tellIt").text = "TIME UP"
_movie.go(32
end if
if the timer > 350 and sprite(16).visible = 0 then
_movie.go(31)
member ("endIt").text = "LUNCH IS FOR THE BIRDS"
member ("tellIt").text = "TIME FLIES"
end if
if the timer > 350 and sprite(15).visible = 0 then
_movie.go(31)
member ("endIt").text = "LUNCH IS FOR THE BIRDS"
member ("tellIt").text = "TIME FLIES"
end if
if the timer > 350 and sprite(14).visible = 0 then
_movie.go(31)
member ("endIt").text = "LUNCH IS FOR THE BIRDS"
member ("tellIt").text = "TIME FLIES"
end if
if the timer > 350 and sprite(13).visible = 0 then
_movie.go(31)
member ("endIt").text = "LUNCH IS FOR THE BIRDS"
member ("tellIt").text = "TIME FLIES"
end if
if the timer > 350 and sprite(12).visible = 0 then
_movie.go(31)
member ("endIt").text = "LUNCH IS FOR THE BIRDS"
member ("tellIt").text = "TIME FLIES"
end if
--
This code is written on the movie script.
I really hope you can steer me in the right direction as I don't have a clue why it's not going to the frame I am asking it to. Everything else in the game appears to be working fine.
The way you have it, it doesn't matter how many of the first checks are true, if any one of the later checks are true, then you're going to end up at frame 31.
If you put an 'exit' in each of the if statements, that will make sure that the later checks are not done. Like:
if the timer >= 360 and sprite(16).visible = 1 then
member ("tellIt").text = "TIME UP"
_movie.go(32)
exit
end if
Related
*data final;
set final;
duration = redate-ondate;
dudays = floor(duration/86400);
duhrs = floor((duration-(dudays*86400))/3600);
dumins = floor((duration-(dudays*86400+duhrs*3600))/60);
****************Set up new variable duration**************;
attrib dur length=$11.;
if ae_term ne 'None' and dudays ne . then
dur = left(put(dudays,z2.))||':'||left(put(duhrs,z2.))||':'||left(put(dumins,z2.));
else dur = '';
run;*
I have this code but need to calculate seconds and concatenate to dur as I have an adverse event that is less than a minute so won't display. What's the most efficient way to do this?
You can calculate the remaining seconds and then append to your time string like this:
dusec = duration-(dudays*86400+duhrs*3600+dumins*60);
if ae_term ne 'None' and dudays ne . then
dur = left(put(dudays,z2.))||':'||left(put(duhrs,z2.))||':'||left(put(dumins,z2.)||':'||left(put(dusec,z2.)));
One note - using put(dudays,z2.) assumes your duration is never more than 99 days.
Ok, this should simplify things somewhat:
dudays = FLOOR(duration/86400);
duhrs = FLOOR(MOD(duration,86400)/3600);
dumins = FLOOR(MOD(duration,3600)/60);
dusec = MOD(duration,60);
The difference between two datetime values is a number of seconds (so it is also a datetime value). You can use the DATEPART() and TIMEPART() function to divide into the number of days and seconds since midnight. The TOD11.2 format will display seconds in HH:MM:SS.mm style.
length dur $20;
if n(redate,ondate)=2 and ae_term not in (' ','None') then do;
duration = redate-ondate;
dur = catx(':',datepart(duration),put(timepart(duration),tod11.2));
end;
If i run Stata's timer:
timer on 1
(code lines)
timer off 1
timer list 1
I cannot read the result:
timer list 1
1: 325.15 / 2 = 162.5725
The next time the timer produces:
timer list 1
1: 622.47 / 3 = 207.4883
It seems it is dividing 325.15 by 2, dividing 622.47 by 3.
Why? What does pre-division number mean? What does post-division number mean?
I tried reading the manual on the topic and other information online but I couldn't find any answer.
The first number is the time elapsed in seconds and the second is the number of times the timer was turned on and off.
Using the example from the help file:
program tester
version 13
forvalues repeat=1(1)100 {
timer on 1
quietly summarize price
timer off 1
}
timer list 1
return list
end
And the toy dataset auto.dta:
sysuse auto, clear
timer clear 1
tester
1: 0.01 / 100 = 0.0001
scalars:
r(N) = 74
r(sum_w) = 74
r(mean) = 6165.256756756757
r(Var) = 8699525.974268788
r(sd) = 2949.495884768919
r(min) = 3291
r(max) = 15906
r(sum) = 456229
r(t1) = .008
r(nt1) = 100
tester
1: 0.02 / 200 = 0.0001
scalars:
r(N) = 74
r(sum_w) = 74
r(mean) = 6165.256756756757
r(Var) = 8699525.974268788
r(sd) = 2949.495884768919
r(min) = 3291
r(max) = 15906
r(sum) = 456229
r(t1) = .017
r(nt1) = 200
If you clear the timer again:
timer clear 1
tester
1: 0.01 / 100 = 0.0001
scalars:
r(N) = 74
r(sum_w) = 74
r(mean) = 6165.256756756757
r(Var) = 8699525.974268788
r(sd) = 2949.495884768919
r(min) = 3291
r(max) = 15906
r(sum) = 456229
r(t1) = .007
r(nt1) = 100
I have 2 variables where I get 2 times from datePicker and I need to save on a variable the difference between them.
let timeFormatter = DateFormatter()
timeFormatter.dateFormat = "HHmm"
time2 = timeFormatter.date(from: timeFormatter.string(from: datePicker.date))!
I have tried to get the timeIntervalSince1970 from both of them and them substract them and get the difference on milliseconds which I will turn back to hours and minutes, but I get a very big number which doesn't corresponds to the actual time.
let dateTest = time2.timeIntervalSince1970 - time1.timeIntervalSince1970
Then I have tried using time2.timeIntervalSince(date: time1), but again the result milliseconds are much much more than the actual time.
How I can get the correct time difference between 2 times and have the result as hours and minutes in format "0823" for 8 hours and 23 minutes?
The recommended way to do any date math is Calendar and DateComponents
let difference = Calendar.current.dateComponents([.hour, .minute], from: time1, to: time2)
let formattedString = String(format: "%02ld%02ld", difference.hour!, difference.minute!)
print(formattedString)
The format %02ld adds the padding zero.
If you need a standard format with a colon between hours and minutes DateComponentsFormatter() could be a more convenient way
let formatter = DateComponentsFormatter()
formatter.allowedUnits = [.hour, .minute]
print(formatter.string(from: time1, to: time2)!)
TimeInterval measures seconds, not milliseconds:
let date1 = Date()
let date2 = Date(timeIntervalSinceNow: 12600) // 3:30
let diff = Int(date2.timeIntervalSince1970 - date1.timeIntervalSince1970)
let hours = diff / 3600
let minutes = (diff - hours * 3600) / 60
To get duration in seconds between two time intervals, this can be used -
let time1 = Date(timeIntervalSince1970: startTime)
let time2 = Date(timeIntervalSince1970: endTime)
let difference = Calendar.current.dateComponents([.second], from: time1, to: time2)
let duration = difference.second
Now you can do it in swift 5 this way,
func getDateDiff(start: Date, end: Date) -> Int {
let calendar = Calendar.current
let dateComponents = calendar.dateComponents([Calendar.Component.second], from: start, to: end)
let seconds = dateComponents.second
return Int(seconds!)
}
How can i remove weekdays in the data type duration in CAL ?
for example:
duration := datetime2 - datetime1
But duration do contains Saturdays and Sundays. How can i remove them ?
Simple answer: you can not.
But you can use the Date virtual table. Something like this:
Date.SETRANGE("Period Type", Date."Period Type"::Date);
Date.SETFILTER("Period Start", '%1..%2', DT2DATE(datetime1), DT2DATE(datetime2));
Date.SETRANGE("Period No.", 1, 5); // only days 1 - 5 = weekdays
EXIT(Date.COUNT); // returns number of days
You can then convert the number of days to a duration with a simple multiplication. A Duration is nothing more than the number of milliseconds.
1 hour = 3600000ms.
Therefore:
MESSAGE('%1', NoOfDays);
dur := NoOfDays * 24 * 3600 * 1000;
MESSAGE('%1', dur);
I have a data frame that is composed of several datasets (about 146 and counting). two of my columns are labeled "start_time" and "stop_time," which represent the start and stop of a response (i.e., the total duration of the response).
I need to get the "inter-response time" or the start_time subtracted from the next corresponding value in start_time. Basically if:
start_time = [1,4,7]
stop_time = [2,5,8]
I need:
stop_time[0] - start_time[1]
stop_time[2] - start_time[3]
in order to get:
iri = [2,2]
My code looks like this:
iri_t = []
def grps():
for grp in lset2_name_grps.groups:
beg_eng_t = pd.DataFrame([lset2_name_grps.stop_time, lset2_name_grps.start_time], columns=['end_t','beg_t'])
end_t = [i for i in lset2_name_grps.stop_time]
beg_t = [i for i in lset2_name_grps.start_time]
beg_t = np.insert(beg_t, len(beg_t),0)
end_t = np.insert(end_t, 0,0)
iri_t.append(np.subtract(end_t, beg_t))
# for i,j in zip(end_t, beg_t):
# iri_t.append(np.subtract(i,j))
# lset2_name_grps['iri'] = iri_t
grps()
Essentially, it doesn't do anything close to what I'm trying to accomplish and the only out I get is either "Not Implemented" or an error.
How about something like this:
import pandas as pd
starts = pd.Series([1, 4, 7])
stops = pd.Series([2, 5, 8])
iri_t = [0]
for i in range(1, len(starts)):
iri_t.append(starts[i] - ends[i-1])
times_df = pd.concat([starts, stops, pd.Series(iri_t)], axis=1)
This creates the following data_frame:
0 1 2
0 1 2 0
1 4 5 2
2 7 8 2
I think what your asking (correct me if I'm wrong) is best accomplished by putting the two columns in a single dataframe, using shift to offset one of your columns, then doing an ordinary subtraction.
df = pd.DataFrame({'start_time':[1,4,7], 'stop_time':[2,5,8]})
df.stop_time - df.start_time.shift()
Out[5]:
0 NaN
1 4
2 4
dtype: float64