Code:
begin ab01bookSwapScript
; example of global script
; should randomly swap/cycle weekly (PERSISTENT)
; ab01BookA1, ab01BookA2, ab01BookA3, ab01BookA4
; and ab01BookB1, ab01BookB2, ab01BookB3, ab01BookB4
short myDay
short myDaysPassed
short i1
short i2
short state
short z1
short z2
if ( myDay == Day )
return
endif
; a day has passed
set myDay to Day
set myDaysPassed to ( myDaysPassed + 1 )
if ( myDaysPassed <= 7 )
return
endif
; a week has passed
set myDaysPassed to 0 ; reset week counter
if ( state == 0 )
set state to 1 ; random books by default
; set state to 2 ; uncomment this to cycle books instead of randomize
; one time storage of book start position
set z1 to ( ab01BookA1->GetPos Z )
set z2 to ( ab01BookB1->GetPos Z )
endif
if ( state == 1 )
; assign random books by default
set i1 to Random 10001
set i1 to ( i1 * 0.0003 ) ; 0 <= i1 <= 3
set i2 to Random 1001
set i2 to ( i2 * 0.003 ) ; 0 <= i2 <= 3
elseif ( state == 2 )
; cycle books
set i1 to ( i1 + 1 )
if ( i1 > 3 )
set i1 to 0
endif
set i2 to ( i2 + 1 )
if ( i2 > 3 )
set i2 to 0
endif
endif
if ( i1 == 0 )
ab01BookA4->SetPos Z -300 ; move it to avoid collision problems
ab01BookA4->Disable ; then disable
ab01BookA3->SetPos Z -300
ab01BookA3->Disable
ab01BookA2->SetPos Z -300
ab01BookA2->Disable
ab01BookA1->SetPos Z z1 ; move the book to right position
ab01BookA1->Enable ; display it
elseif ( i1 == 1 )
ab01BookA4->SetPos Z -300
ab01BookA4->Disable
ab01BookA3->SetPos Z -300
ab01BookA3->Disable
ab01BookA1->SetPos Z -300
ab01BookA1->Disable
ab01BookA2->SetPos Z z1
ab01BookA2->Enable
elseif ( i1 == 2 )
ab01BookA4->SetPos Z -300
ab01BookA4->Disable
ab01BookA2->SetPos Z -300
ab01BookA2->Disable
ab01BookA1->SetPos Z -300
ab01BookA1->Disable
ab01BookA3->SetPos Z z1
ab01BookA3->Enable
else ; if ( i1 == 3 )
ab01BookA3->SetPos Z -300
ab01BookA3->Disable
ab01BookA2->SetPos Z -300
ab01BookA2->Disable
ab01BookA1->SetPos Z -300
ab01BookA1->Disable
ab01BookA4->SetPos Z z1
ab01BookA4->Enable
endif
if ( i2 == 0 )
ab01BookB4->SetPos Z -300
ab01BookB4->Disable
ab01BookB3->SetPos Z -300
ab01BookB3->Disable
ab01BookB2->SetPos Z -300
ab01BookB2->Disable
ab01BookB1->SetPos Z z2
ab01BookB1->Enable
return
elseif ( i2 == 1 )
ab01BookB4->SetPos Z -300
ab01BookB4->Disable
ab01BookB3->SetPos Z -300
ab01BookB3->Disable
ab01BookB1->SetPos Z -300
ab01BookB1->Disable
ab01BookB2->SetPos Z z2
ab01BookB2->Enable
return
elseif ( i2 == 2 )
ab01BookB4->SetPos Z -300
ab01BookB4->Disable
ab01BookB2->SetPos Z -300
ab01BookB2->Disable
ab01BookB1->SetPos Z -300
ab01BookB1->Disable
ab01BookB3->SetPos Z z2
ab01BookB3->Enable
return
else ; if ( i2 == 3 )
ab01BookB3->SetPos Z -300
ab01BookB3->Disable
ab01BookB2->SetPos Z -300
ab01BookB2->Disable
ab01BookB1->SetPos Z -300
ab01BookB1->Disable
ab01BookB4->SetPos Z z2
ab01BookB4->Enable
endif
end
Cheers!