// Henjin State Demo // (c) 2008, Notequalsoft Games // http://www.notequalsoft.com/games/henjin/ // This demo demonstrates the concept of saving and loading states. // setup system System.Size 640 480 System.Continue true System.CreateImage WaitImage 619 460 18 17 "waiting.gif" System.WaitImage WaitImage System.CreateViewPort ViewPort 0 0 640 480 ViewPort.CreateCanvas Canvas 0 0 640 400 System.CreateTextBox TextBox 0 400 640 80 TextBox.DisplayAtOnce true // set up a progress bar that will simulate a stateful process Canvas.CreateProgressBar ProgressBar 10 10 620 30 ProgressBar.Background #808080 ProgressBar.Maximum 255 set Minus1 = 0 set Minus2 = 0 // set up some buttons to control state Canvas.CreateButton LoadButton1 20 100 180 50 "Load 1" LoadButton1.OnClickGoTo LOAD1 Canvas.CreateButton SaveButton1 20 170 180 50 "Save 1" SaveButton1.OnClickGoTo SAVE1 Canvas.CreateButton DeleteButton1 20 240 180 50 "Delete 1" DeleteButton1.OnClickGoTo DELETE1 Canvas.CreateButton LoadButton2 230 100 180 50 "Load 2" LoadButton2.OnClickGoTo LOAD2 Canvas.CreateButton SaveButton2 230 170 180 50 "Save 2" SaveButton2.OnClickGoTo SAVE2 Canvas.CreateButton DeleteButton2 230 240 180 50 "Delete 2" DeleteButton2.OnClickGoTo DELETE2 Canvas.CreateButton CopyButton2 230 310 180 50 "Copy 2" CopyButton2.OnClickGoTo COPY2 Canvas.CreateButton LoadButton3 440 100 180 50 "Load 3" LoadButton3.OnClickGoTo LOAD3 Canvas.CreateButton SaveButton3 440 170 180 50 "Save 3" SaveButton3.OnClickGoTo SAVE3 Canvas.CreateButton DeleteButton3 440 240 180 50 "Delete 3" DeleteButton3.OnClickGoTo DELETE3 Canvas.CreateButton CopyButton3 440 310 180 50 "Copy 3" CopyButton3.OnClickGoTo COPY3 // update button visbility label UPDATE_BUTTON_VISIBILITY LoadButton1.Enabled "{stateexists:state1}" DeleteButton1.Enabled "{stateexists:state1}" LoadButton2.Enabled "{stateexists:state2}" DeleteButton2.Enabled "{stateexists:state2}" CopyButton2.Enabled "{stateexists:state1}" LoadButton3.Enabled "{stateexists:state3}" DeleteButton3.Enabled "{stateexists:state3}" CopyButton3.Enabled "{stateexists:state1}" // display progress bar value label WAIT_FOR_CLICK TextBox.Text "Current = {ProgressBar.Value}\nPrevious = {Minus1}\nPrevious Previous = {Minus2}" react // add a random value between 5 and 50 to the progress bar value and repeat if ProgressBar.Value = 255 set value = 0 else set value = ProgressBar.Value endif set rnd random 45 set rnd add 5 set value add rnd if value > 255 set value = 255 endif set Minus2 = Minus1 set Minus1 = ProgressBar.Value Progressbar.Value value sethex valuehex value setlength valuehexlength valuehex if valuehexlength < 2 set valuehex = "0{valuehex}" endif Canvas.Background "#{valuehex}{valuehex}{valuehex}" goto WAIT_FOR_CLICK // load first state label LOAD1 loadstate state1 // save first state label SAVE1 savestate state1 goto UPDATE_BUTTON_VISIBILITY // delete first state label DELETE1 deletestate state1 goto UPDATE_BUTTON_VISIBILITY // load second state label LOAD2 loadstate state2 // save second state label SAVE2 savestate state2 goto UPDATE_BUTTON_VISIBILITY // delete second state label DELETE2 deletestate state2 goto UPDATE_BUTTON_VISIBILITY // copy first state to second state label COPY2 copystate state1 state2 goto UPDATE_BUTTON_VISIBILITY // load third state label LOAD3 loadstate state3 // save third state label SAVE3 savestate state3 goto UPDATE_BUTTON_VISIBILITY // delete third state label DELETE3 deletestate state3 goto UPDATE_BUTTON_VISIBILITY // copy first state to third state label COPY3 copystate state1 state3 goto UPDATE_BUTTON_VISIBILITY