how to print a whole text file as a movie ending titles (from bottom to top)

New to FreeBASIC? Post your questions here.
Post Reply
ron77
Posts: 213
Joined: Feb 21, 2019 19:24

how to print a whole text file as a movie ending titles (from bottom to top)

Post by ron77 »

hello good day i have a question
i have a text file with a game ending credits
i wish to LINE INPUT it into and array and then print it to the screen (screen 19) as a movie ending credits - i tried but it doesn't work i get a black screen
here are my pieces of code:

Code: Select all

'append to the string array the string item
SUB sAppend (arr() AS STRING, item AS STRING)
    REDIM Preserve arr(LBOUND(arr) TO UBOUND(arr) + 1) AS STRING
    arr(UBOUND(arr)) = item
end sub

'SUB upper (f as string)
'    redim lines(0) as string
'    dim as integer r,c, i
'    dim fline as string
'    OPEN f FOR INPUT AS #1
'    WHILE Not EOF(1)
'        LINE INPUT #1, fline
'        sAppend lines(), fline        
'    wend
'    close #1
'r= 35
'c = 5    
'i = 0
'    DO
        
'        LOCATE r, c
'        PRINT lines(i)
'       _    sleep(100)
'        r = r - 1
'        i = i + 1
'    LOOP UNTIL r = 3 


'Sleep


'end sub
like i said it doesn't work i get a black screen
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: how to print a whole text file as a movie ending titles (from bottom to top)

Post by fxm »

? :

Code: Select all

SUB sAppend (arr() AS STRING, item AS STRING)
    REDIM Preserve arr(0 TO UBOUND(arr) + 1) AS STRING  '' <---
    arr(UBOUND(arr)) = item
end sub
[/s]
[edit]
I misread the ron77's code.
Last edited by fxm on May 30, 2020 20:38, edited 3 times in total.
ron77
Posts: 213
Joined: Feb 21, 2019 19:24

Re: how to print a whole text file as a movie ending titles (from bottom to top)

Post by ron77 »

?XD#!$^%#*()&

this sub appends string rows in to a dynamic array - am i doing something wrong?
badidea
Posts: 2591
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: how to print a whole text file as a movie ending titles (from bottom to top)

Post by badidea »

Works fine:

Code: Select all

'append to the string array the string item
SUB sAppend (arr() AS STRING, item AS STRING)
    REDIM Preserve arr(LBOUND(arr) TO UBOUND(arr) + 1) AS STRING '<-- as string not needed
    arr(UBOUND(arr)) = item
end sub

redim lines() as string '<--- not lines(0)
sAppend lines(), "aaaaaaaa"
sAppend lines(), "bbbbbb"  
sAppend lines(), "ccccccc"    
sAppend lines(), "ddddddddd"   

for i as integer = 0 to ubound(lines)
	print i, lines(i)
next
sleep
Last edited by badidea on May 30, 2020 9:51, edited 1 time in total.
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: how to print a whole text file as a movie ending titles (from bottom to top)

Post by fxm »

I corrected the first line of 'sAppend'.

[edit]
I misread the ron77's code.
Last edited by fxm on May 30, 2020 20:39, edited 2 times in total.
ron77
Posts: 213
Joined: Feb 21, 2019 19:24

Re: how to print a whole text file as a movie ending titles (from bottom to top)

Post by ron77 »

well thank you but that's not what i need i need to print FROM BOTTOM OF SCREEN TO THE TOP OF THE SCREEN
THAT THE TEXT WILL GO UP 1 SEC OR SO WITH ANOTHER ROW (DO YOU REMEMBER MOVIE ENDING TITLES? LIKE THAT)
ron77
Posts: 213
Joined: Feb 21, 2019 19:24

Re: how to print a whole text file as a movie ending titles (from bottom to top)

Post by ron77 »

his works but not correctly the start lines are from bottom to up when i need the lines of the text file to move from start to end from bottom to top.. :(

Code: Select all

SUB upper (f as string)
	cls
	redim lines(0) as string
	dim h as long = freefile()
	dim as integer r =35,c =30
	dim fline as string
	OPEN f FOR INPUT AS #h
	WHILE Not EOF(1)
        LINE INPUT #h, fline
		sAppend lines(), fline		
    wend
	close #h

	for i as integer = 0 to ubound(lines)
		color 7
		locate r, c
		print lines(i)
		sleep 100
		color 0
		locate r,c
		print lines(i)
		r -= 1
		color 7
		locate r, c
		print lines(i)
		sleep 100
	next 


Sleep
end sub
badidea
Posts: 2591
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: how to print a whole text file as a movie ending titles (from bottom to top)

Post by badidea »

The easy way is to let the console do the scrolling up:

Code: Select all

'append to the string array the string item
sub sAppend (arr() as string, item as string)
	redim preserve arr(lbound(arr) to ubound(arr) + 1)
	arr(ubound(arr)) = item
end sub

sub readfile(f as string, lines() as string)
	dim fline as string
	open f for input as #1
	while not eof(1)
		line input #1, fline
		sAppend lines(), fline       
	wend
	close #1
end sub

sub upper (lines() as string)
	dim as integer h = hiword(width()) 'num columns on display
	'print closing credits
	for i as integer = 0 to ubound(lines)
		locate h, 10
		print lines(i)
		sleep 100
	next
	'clear screen
	for i as integer = 1 to h
		print
		sleep 100
	next
end sub

dim lines() as string
readfile("test.bas", lines())
upper(lines())

print "End"
getkey()
ron77
Posts: 213
Joined: Feb 21, 2019 19:24

Re: how to print a whole text file as a movie ending titles (from bottom to top)

Post by ron77 »

oh man that's exactly what i needed thank you so much <3

:))
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: how to print a whole text file as a movie ending titles (from bottom to top)

Post by dodicat »

You use screen 19, then draw string.

Code: Select all

'append to the string array the string item
SUB sAppend (arr() AS STRING, item AS STRING)
    REDIM Preserve arr(LBOUND(arr) TO UBOUND(arr) + 1) AS STRING '<-- as string not needed
    arr(UBOUND(arr)) = item
end sub

redim lines() as string '<--- not lines(0)
for n as long=1 to 10
sAppend lines(), "Badidea"+"      "+iif(rnd>.5,"Good idea","Great idea")
sAppend lines(), "Fxm"+"      "+iif(rnd>.5,"Good idea","Great idea")
sAppend lines(), "Dodicat"+"      "+iif(rnd>.5,"Good idea","Crap")
sAppend lines(), "Ron 77"+"      "+iif(rnd>.5,"Good idea","Great idea")
next n

dim as string s
for n as long=lbound(lines) to ubound(lines)
  s+=str(n)+"  "+lines(n)+"|"
next

sub drawstring(x as long,y as long,s as string,col as ulong=0,im as any ptr=0)
    dim as long dx=x,dy=y,_pos,count=0
    for z as long=0 to len(s)-1
        _pos=dx+8*count
        if s[z]=124 then
            count=0
            dy=dy+16
            goto skip
        end if
        draw string im,(_pos,dy),chr(s[z]),col
        count=count+1
        skip:
        next z
    end sub

screen 19
dim as single z
do
  z+=.1
  screenlock
  cls
  drawstring(10,600-z-50,s,15)
  screenunlock
  sleep 1
  loop until z>600

sleep 
badidea
Posts: 2591
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: how to print a whole text file as a movie ending titles (from bottom to top)

Post by badidea »

dodicat wrote:You use screen 19, then draw string.
I would have expected a Star Wars style credits scrolling form you :-)
Never mind, that has been done before: Another star wars like intro
Post Reply