Scrollable message logbook

Post Reply
Posts: 793
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Location: Groningen, Netherlands
Flag: Netherlands

Scrollable message logbook

Post by Henko »

In (old time) text oriented games like Hamurabi and Eliza, textual (and embedded numeric) information is passed to the user at each iteration.
It is handy to have a message window where new information is added to the bottom of the window, while pushing up the earlier messages. A sB LIST is used to display the messages and retain the history with an user specified capacity. The message list in the window is scrollable.

Three functions are provided-
msg() - the user has to define the window and list in the yellow area
put_msg(a$) - adds message a$ to the logbook and displays it
c_list(....) - low level function, not for the user

The user is responsible for formatting the messages such that they fit in the specified width of the message window.
The message window is meant to be permanent on the screen. However, it may be removed by HIDING the list and do a GRAPHICS CLEAR over the window. Each put_msg() call will restore the message window.

F81EED64-323D-42E0-8B2C-81AFFAAF6512.png (379.14 KiB) Viewed 1707 times

Code: Select all

' Demo of scrollable message logbook
graphics ! graphics clear .8,.8,.8 ! draw color 0,0,0
button "stop" text "Stop" at 600,900 size 60,30
msg()   ' *** initialize the message window
  for i=1 to 195 ! put_msg(nonsense$()) ! next i  ' *** fill table fast
  put_msg(nonsense$())   '  generate and add a (nonsense) message
  pause rnd(1)
  if rnd(1)<.2 then pause 6    '  long pause to enable list scrolling
  until button_pressed("stop")

def msg()   ' *** define name, position, size of the message window
nmax=200         ' max # of kept messages in the (FIFO) table
dim txt$(nmax+1) ' table with messages
n$  ="msg"       ' name (handle) of the list
t$  ="Messages"  ' title of the list
x   =300         ' x position of the left upper window corner
y   =200         ' y position
w   =400         ' width
h   =500         ' height (determines the # of displayed messages)
end def 

def put_msg(a$)
pt+=1 ! if pt>msg.nmax then pt=1 ! m+=1 ! msg.txt$(pt)=m & " " & a$
'  list msg.n$ show   In case that the list is temporarily hidden
end def

' id$ = object name
' cont$ = array met elementen
' size = aantal elementen in de list
' pt = current pointer
def c_list(id$,title$,cont$(),size,pt,xt,yt,w,h)
if pt=size then full=1
if full then dm=size+1 else dm=pt+1
dim temp$(dm)
if full then
  for i=pt+1 to size ! k+=1 ! temp$(k)=cont$(i) ! next i
  end if
for i=1 to pt ! k+=1 ! temp$(k)=cont$(i) ! next i
list id$ text temp$ at xt+2,yt+32 size w-4,h-34
list id$ select k
draw size 3
draw rect xt,yt to xt+w,yt+h ! draw line xt,yt+30 to xt+w,yt+30
draw color 0,0,1
draw text title$ at (2*xt+w-text_width(title$))/2,yt+5 
end def

def nonsense$()  ' **** used for the demo only
a$="abcd efgh ijklm nopq rstu vwx yz " ! la=len(a$) ! b$=""
for nc=1 to 30+rnd(11) ! b$&=mid$(a$,rnd(la),1) ! next nc
return b$
end def

User avatar
Posts: 1337
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada

Re: Scrollable message logbook

Post by rbytes »

An efficient way to keep notes. This may be my opportunity to finally win a game! :roll:
The only thing that gets me down is gravity...

Post Reply