Main Menu

The WAIT command

Started by geecee, February 27, 2009, 06:35:09 PM

Previous topic - Next topic

geecee


What I am trying to do here is print out the letters of the message one at a time with a brief WAIT between each one but I am not getting the desired result.  Any suggestions ...... or am I attempting the impossible?


Message$="Hello! My name is geecee and I am new to Play Basic"

L=len(message$)
Width=gettextwidth(message$)
across=400-width/2

For a=1 to L
  ;wait 100
  charwidth=gettextwidth(mid$(message$,a,1))
  across=across+charwidth
  setcursor across,300
  wait 10
  print mid$(message$,a,1)
  ;wait 100
next



???
Thanks
geecee
LANG MEY YER LUM REEK

A smile costs less than electricity and gives more light :)

micky4fun

#1
Hi geecee

thanks for a post that i can post answer back to , you are my first one ,
yep the sync command is missing , good luck with your programming ..
mick :)

Message$="Hello! My name is micky4fun and here is the answer"

L=len(message$)
Width=gettextwidth(message$)
across=400-width/2

For a=1 to L
  ;wait 100
  charwidth=gettextwidth(mid$(message$,a,1))
  across=across+charwidth
  setcursor across,300
  wait 100
  print mid$(message$,a,1)
  sync
; wait 100
next

waitkey

geecee

Thanks for your reply micky4fun.

:-[
So the SYNC command is necessary before the WAIT command  ...... Silly me.

geecee Error Missing Closing Square Bracket
LANG MEY YER LUM REEK

A smile costs less than electricity and gives more light :)

Makeii Runoru

Now remember, WAIT will stop all process and sleep for a given time before continuing everything again. If you have other things going on in a DO loop, WAIT is not really recommended. You could make your own variable that serves as a timer, decreasing the timer every frame (if in a DO loop that is).

I dont have the PB library reference on me right now, so I can't go too in depth. Sorry.
This signature is boring, and could be improved. However, the user of this signature doesn't need a fancy signature because he or she doesn't really care for one.

geecee

Thanks for your reply Makeii Runoru

geecee
LANG MEY YER LUM REEK

A smile costs less than electricity and gives more light :)

kevin



Message$="Hello! My name is geecee and I am new to Play Basic"

L=len(message$)
Width=gettextwidth(message$)
across=400-width/2

For a=1 to L
  ;wait 100
  charwidth=gettextwidth(mid$(message$,a,1))
  across=across+charwidth
  setcursor across,300
  print mid$(message$,a,1)

  // Show the screens backbuffer to the user
  sync

  // 10 millisecond wait ='s about 100th of  second
  wait 10

next




  but you can reduce the above down to


setfps 100

Message$="Hello! My name is geecee and I am new to Play Basic"

across=400-gettextwidth(message$)/2

For a=1 to len(message$)
  text across,300, left$(message$,a)
  sync
next


geecee

Thanks for your reply kevin.

The second example must surely be the simplest way of achieving the desired result.

If you don't mind I will use this in my programmes.

Much appreciated.  :D

geecee
LANG MEY YER LUM REEK

A smile costs less than electricity and gives more light :)

kevin


go for it. 


This one is a little more complicated, but will hopefully get you used to the idea of how we can manage  items in unison.





setfps 60

Message$="Hello! My name is geecee and I am new to Play Basic"

loadfont "arial",1,32,0


Do

// clear the screen
Cls rgb(0,30,40)

// Draw some other element
BaseAngle#=wrapangle(Baseangle#,1)
Balls=12
for lp =0 to Balls-1
Angle#=BaseAngle#+(lp*(360/Balls))
x#=400+cosRadius(angle#,70)
y#=300+SinRadius(angle#,70)
circle x#,y#,20,true
next


// draw the type writer text
Chrpos=TypeTExt(100,100,Message$,ChrPos)

Sync
loop



Function TypeTExt(xpos,ypos,Message$,ChrPos)
Static CursorBlink,CursorBlinkTime

s$=Left$(Message$,ChrPos)
Text Xpos,ypos,s$

if CursorBlinkTime<Timer()
CursorBlinkTime=Timer()+250+rnd(250)
CursorBlink=1-CursorBlink
endif

if CursorBlink
Xpos2=Xpos+GetTextWidth(s$)
H=GetTExtHeight(s$)
Line Xpos2,Ypos,xpos2,Ypos+h
endif

if ChrPOs<len(Message$)
inc ChrPos
endif

EndFunction ChrPos




geecee

Thanks for your reply kevin.

That one will take a bit of studying and understanding.

Much appreciated.
geecee
LANG MEY YER LUM REEK

A smile costs less than electricity and gives more light :)