Using a delay in a stringgadget between changing

Just starting out? Need help? Post your questions and find answers here.
Fangles
Posts: 11
Joined: Sat Jan 28, 2017 4:25 am

Using a delay in a stringgadget between changing

Post by Fangles »

Just started with SpiderBasic to see if I can pick it up and don't actually know anything.

For the hell of it, I wanted to read some strings from a datasection and set them to a stringgadget with a delay between each string and have tried a few things including timers and nothing works predictably as he rules are different.

In the procedure DoSillyStrings, how do I introduce a delay of a few seconds between each string? Yes, I know the timer doesn't work, I tried it:):)

I know nothing about SB!!! (But am hopeful)

Code: Select all

Define EventID, MenuID, GadgetID, WindowID

Enumeration 1
  #Window_Hellotest
EndEnumeration

#WindowIndex = #PB_Compiler_EnumerationValue

Enumeration 1
  #Gadget_Hellotest_cHello
  #Gadget_Hellotest_lHellotext
  #Gadget_Hellotest_Hellotext
  #Gadget_Hellotest_cControl
  #Gadget_Hellotest_bStart
  #Gadget_Hellotest_bExit
EndEnumeration

#GadgetIndex = #PB_Compiler_EnumerationValue

Procedure.i Window_Hellotest()
  If OpenWindow(#Window_Hellotest,228,111,320,120,"Android hello test",#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_Invisible)
    ContainerGadget(#Gadget_Hellotest_cHello,10,10,300,40,#PB_Container_Flat|#PB_Container_BorderLess)
      SetGadgetColor(#Gadget_Hellotest_cHello,#PB_Gadget_BackColor,$C0C0C0)
    TextGadget(#Gadget_Hellotest_lHellotext,5,10,80,15,"Silly message",#PB_Text_Center)
      SetGadgetColor(#Gadget_Hellotest_lHellotext,#PB_Gadget_BackColor,$C0C0C0)
    StringGadget(#Gadget_Hellotest_Hellotext,90,5,200,20,"",#PB_String_ReadOnly|#PB_String_BorderLess)
      SetGadgetColor(#Gadget_Hellotest_Hellotext,#PB_Gadget_BackColor,$C0C0C0)
    CloseGadgetList()
    ContainerGadget(#Gadget_Hellotest_cControl,10,60,300,50,#PB_Container_Flat|#PB_Container_BorderLess)
      SetGadgetColor(#Gadget_Hellotest_cControl,#PB_Gadget_BackColor,$D7D7D7)
    ButtonGadget(#Gadget_Hellotest_bStart,10,15,130,20,"Start Sillyness")
    ButtonGadget(#Gadget_Hellotest_bExit,160,15,130,20,"Exit sillyness")
    CloseGadgetList()
    HideWindow(#Window_Hellotest,0)
    ProcedureReturn WindowID(#Window_Hellotest)
  EndIf
EndProcedure

Global Dim GlowColours(11)

GlowColours(0)  = $0000FF
GlowColours(1)  = $00FF00
GlowColours(2)  = $00FFFF
GlowColours(3)  = $FF0000
GlowColours(4)  = $FF00FF
GlowColours(5)  = $FFFF00
GlowColours(6)  = $000080
GlowColours(7)  = $008000
GlowColours(8)  = $800000
GlowColours(9)  = $800080
GlowColours(10) = $808000
GlowColours(11) = $000000

Declare DoSillyStrings()

Procedure CloseWindowEvent()
  WindowID = EventWindow()
  If WindowID = #Window_Hellotest
    CloseWindow(#Window_Hellotest)
  EndIf
EndProcedure

Procedure GadgetEvent()
  GadgetID = EventGadget()
  Select GadgetID
    Case #Gadget_Hellotest_bStart : DoSillyStrings()
    Case #Gadget_Hellotest_bExit  : CloseWindow(#Window_Hellotest)
  EndSelect
EndProcedure

Procedure DoSillyStrings()
  Restore StartSillyStrings
  While TempString.s <> "_EndSillyStrings_"
    If EventTimer() = 33
      Read.s TempString.s
      If TempString.s <> "_EndSillyStrings_"
        SetGadgetText(#Gadget_Hellotest_Hellotext, TempString.s)
        SetGadgetColor(#Gadget_Hellotest_Hellotext, #PB_Gadget_FrontColor, Random(GlowColours()))
      EndIf
    EndIf
  Wend
  TempString.s = "<>"  
EndProcedure

If Window_Hellotest()
  BindEvent(#PB_Event_Gadget, @GadgetEvent())
  AddWindowTimer(#Window_Hellotest, 33, 2000)
EndIf

DataSection
  StartSillyStrings:
  Data.s "You"
  Data.s "are"
  Data.s "a"
  Data.s "hairy"
  Data.s "smeg"
  Data.s "brained"
  Data.s "mongoose"
  Data.s "biter"
  Data.s "with"
  Data.s "a"
  Data.s "lizard"
  Data.s "extension"
  Data.s "up"
  Data.s "ya"
  Data.s "hairy"
  Data.s "buttcrack"
  Data.s  "_EndSillyStrings_"
EndDataSection
Last edited by Fangles on Tue Feb 07, 2017 10:56 am, edited 1 time in total.
User avatar
Peter
Posts: 1197
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: Using a delay in a stringgadget between changing

Post by Peter »

this is an example using a timer:

Code: Select all

EnableExplicit

Enumeration 1
  #Window_Hellotest
EndEnumeration

Enumeration 1
  #Gadget_Hellotest_cHello
  #Gadget_Hellotest_lHellotext
  #Gadget_Hellotest_Hellotext
  #Gadget_Hellotest_cControl
  #Gadget_Hellotest_bStart
  #Gadget_Hellotest_bExit
EndEnumeration

Procedure.i Window_Hellotest()
  If OpenWindow(#Window_Hellotest,228,111,320,120,"Android hello test",#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_Invisible)
    ContainerGadget(#Gadget_Hellotest_cHello,10,10,300,40,#PB_Container_Flat|#PB_Container_BorderLess)
    SetGadgetColor(#Gadget_Hellotest_cHello,#PB_Gadget_BackColor,$C0C0C0)
    TextGadget(#Gadget_Hellotest_lHellotext,5,10,80,15,"Silly message",#PB_Text_Center)
    SetGadgetColor(#Gadget_Hellotest_lHellotext,#PB_Gadget_BackColor,$C0C0C0)
    StringGadget(#Gadget_Hellotest_Hellotext,90,5,200,20,"",#PB_String_ReadOnly|#PB_String_BorderLess)
    SetGadgetColor(#Gadget_Hellotest_Hellotext,#PB_Gadget_BackColor,$C0C0C0)
    CloseGadgetList()
    ContainerGadget(#Gadget_Hellotest_cControl,10,60,300,50,#PB_Container_Flat|#PB_Container_BorderLess)
    SetGadgetColor(#Gadget_Hellotest_cControl,#PB_Gadget_BackColor,$D7D7D7)
    ButtonGadget(#Gadget_Hellotest_bStart,10,15,130,20,"Start Sillyness")
    ButtonGadget(#Gadget_Hellotest_bExit,160,15,130,20,"Exit sillyness")
    CloseGadgetList()
    HideWindow(#Window_Hellotest,0)
    ProcedureReturn WindowID(#Window_Hellotest)
  EndIf
EndProcedure

Global Dim GlowColours(11)

GlowColours(0) = $0000FF
GlowColours(1) = $00FF00
GlowColours(2) = $00FFFF
GlowColours(3) = $FF0000
GlowColours(4) = $FF00FF
GlowColours(5) = $FFFF00
GlowColours(6) = $000080
GlowColours(7) = $008000
GlowColours(8) = $800000
GlowColours(9) = $800080
GlowColours(10) = $808000
GlowColours(11) = $000000



Procedure CloseWindowEvent()
  Protected WindowID = EventWindow()
  If WindowID = #Window_Hellotest
    CloseWindow(#Window_Hellotest)
  EndIf
EndProcedure

Procedure TimerEvent()
  
  Protected TempString.s
  
  Read.s TempString
  
  If TempString = "_EndSillyStrings_"
    Restore StartSillyStrings
    TimerEvent()
    ProcedureReturn
  EndIf
  
  SetGadgetText(#Gadget_Hellotest_Hellotext, TempString.s)
  SetGadgetColor(#Gadget_Hellotest_Hellotext, #PB_Gadget_FrontColor, GlowColours(Random(11)))
  
EndProcedure

Procedure GadgetEvent()
  Protected GadgetID = EventGadget()
  Select GadgetID
    Case #Gadget_Hellotest_bStart
      Restore StartSillyStrings
      BindEvent(#PB_Event_Timer, @TimerEvent(), #Window_Hellotest)
      DisableGadget(#Gadget_Hellotest_bStart, #True)
    Case #Gadget_Hellotest_bExit 
      CloseWindow(#Window_Hellotest)
  EndSelect
EndProcedure

If Window_Hellotest()
  BindEvent(#PB_Event_Gadget, @GadgetEvent())
  AddWindowTimer(#Window_Hellotest, 33, 2000)
EndIf

DataSection
  StartSillyStrings:
  Data.s "You"
  Data.s "are"
  Data.s "a"
  Data.s "hairy"
  Data.s "smeg"
  Data.s "brained"
  Data.s "mongoose"
  Data.s "biter"
  Data.s "with"
  Data.s "a"
  Data.s "lizard"
  Data.s "extension"
  Data.s "up"
  Data.s "ya"
  Data.s "hairy"
  Data.s "buttcrack"
  Data.s "_EndSillyStrings_"
EndDataSection
Greetings ... Peter
Fangles
Posts: 11
Joined: Sat Jan 28, 2017 4:25 am

Re: Using a delay in a stringgadget between changing

Post by Fangles »

That's great Peter, thanks. I just hope it doesn't take me 16 years to get as good at SB as I got at PB (Still making stupid mistakes in that too).

Hoping to port my address book over (and other things (one day)
Post Reply