No Text refresh

Find quick help here to get you started with Hollywood
Post Reply
Mr_Blues
Posts: 2
Joined: Thu Jan 15, 2015 12:08 pm

No Text refresh

Post by Mr_Blues »

Hello, i am a beginner and a newbie with hollywood. just i want to make a quiz with hollywood, i take the DaCoolQuiz code and mdify it with my questions. But for longer questions i had to use a larger display and larger buttons, now with the effect that the text in the questions and answerbuttons overwrite the previous text with no refreshig. The irst question you can read in a normal way, but u the secnd question you have only garbage on the screen. What is wrong?
Here the modfied code:
/************************************************** **************
** **
** Name: Silviahemmet Quiz **
** Author: Arnim Wolff **
** Version: 0.1b **
** Date: 13.1.2015 **
** Interpreter: Hollywood 5.3 **
** Licence: Free **
** Function: Kleines Quiz für Freunde der Malteser **
** und um das Wissen um die Demenz **
** History: **
** **
** 0.1: (13.01.2015) **
** **
** - erste Alpha-Version **
** **
** **
************************************************** **************/

/*
** Important! Check if the used Hollywood version is at least
** version 2.0!
*/
@VERSION 2,0

/*
** Brushes
*/
@BRUSH 1, "Title.png"
@BRUSH 2, "Game.png"

/*
** Sounds
*/
@SAMPLE 1, "Good.wav"
@SAMPLE 2, "Poor.wav"
@SAMPLE 3, "True.wav"
@SAMPLE 4, "False.wav"

/*
** The display auskommentiert
*/
@DISPLAY {Width = 640, Height = 480, Title = "USA Quiz", Mode = "Windowed", Color = #WHITE }

/*
** Show main menu
*/
Function p_MainMenu()

Local ypos = 103

DisplayBGPic(1)

MoveBrush(1, #CENTER, #BOTTOMOUT, #CENTER, 0, 5)
SetFontColor(#BLACK)

For Local k = 0 To 319
Plot(k, 95, #BLACK)
Plot(319 - k, 250, #BLACK)

If k > 0 And k % 35 = 0
TextOut(#CENTER, ypos, text$[k \ 35])
ypos = ypos + 17
EndIf

Wait(10, #MILLISECONDS)
Next

t = 10 ; for p_DisplayText()

SetInterval(1, Function() t = Wrap(t + 1, 1, 61) p_DisplayText() EndFunction, 4000)

EndFunction

/*
** update the info text
*/
Function p_DisplayText()

Local ypos = 200

DisplayBGPic(1)
SetFontColor(#BLACK)
While text$[t] <> ""
TextOut(#CENTER, ypos, text$[t])
ypos = ypos + 17
t = t + 1
Wend

EndFunction


Function p_NextQuestion(answer)

Local n

Box(6, 123, 627, 17, IIf(answer = 1, #RED, #BLACK))
Box(6, 151, 627, 18, IIf(answer = 2, #RED, #BLACK))
Box(6, 179, 627, 17, IIf(answer = 3, #RED, #BLACK))
Box(6, 206, 627, 18, IIf(answer = 4, #RED, #BLACK))

Local numfound = False

; look for a question that has not been asked yet
While numfound = False

n = Rnd(q)
If FindStr(questions$[n], "|") <> -1 Then n = n - 1

For Local i = 0 To qc - 1
If ques = n Then Continue(2)
Next

numfound = True
Wend

; store it in the stack of already asked questions
ques[qc] = n
qc = qc + 1

TextOut(#CENTER, 102, questions$[n])
Local ans$ = SplitStr(questions$[n + 1], "|")

; randomly choose which button will hold the correct answer
correct = Rnd(4)
TextOut(#CENTER, 128, ans$[qloc[correct][0]])
TextOut(#CENTER, 156, ans$[qloc[correct][1]])
TextOut(#CENTER, 185, ans$[qloc[correct][2]])
TextOut(#CENTER, 212, ans$[qloc[correct][3]])

correct = correct + 1

EndFunction

Function p_StartGame()

gameon = True

ClearInterval(1) ; stop menu text refresh

DisableButton(1)

DisplayBGPicPart(1, 0, 96, 627, 154)
DisplayBrush(2, 0, 627)

For Local k = 2 To 5 Do EnableButton(k)

; reset question & score counters
qc = 0
score = 0

p_NextQuestion(0)

EndFunction

/*
** Check for correct answer!
*/
Function p_CheckAnswer(answer)

If answer <> correct
If score >= 5 Then score = score - 5
PlaySample(4)
Else
score = score + 5
PlaySample(3)
EndIf

DisplayBrush(2, 0, 627)

; update status text
TextOut(#CENTER, 237, "Questions: " .. qc .. " - Score: " .. score)

; ask 20 questions!
If qc < 20
p_NextQuestion(answer)
Else
p_GameOver()
EndIf

EndFunction

/*
** this function is called after 10 questions were asked
*/
Function p_GameOver()

gameon = False

DisplayBGPicPart(1, 0, 96, 627, 154)

For Local k = 2 To 5 Do DisableButton(k)

Wait(100)

TextOut(#CENTER, 102, "Du hast " .. score .. " Prozentpunkte erreicht!")

SetMargins(6, 315)
Locate(0, 128)

If score >= 100
Print("Einhundert Prozent richtig....Ich bin sprachlos, herzlichen Glückwunsch")
PlaySample(1)
ElseIf score >= 95
Print("Wow, fast alles richtig....sehr gut")
PlaySample(1)
ElseIf score >= 80
Print("Das ist wirklich gut")
PlaySample(1)
ElseIf score >= 65
Print("Nett...aber da geht noch was")
PlaySample(1)
ElseIf score >= 50
Print("Ausbaufähig, das geht noch deutlich besser")
PlaySample(1)
ElseIf score >= 25
Print("Also ehrlich gesagt, ein wenig lernen")
PlaySample(2)
Else
Print("Oh weh, das heißt noch üben,üben,üben oder besser raten")
PlaySample(2)
EndIf

TextOut(#CENTER, 237, "Drücke den linken Maus-Knopf")
WaitLeftMouse

; restart!
p_MainMenu()

EnableButton(1)

EndFunction

/*
** the event func will be entered when a button is pressed
*/
Function p_EventFunc(msg)

; are we in game mode or not?
If gameon = False

If msg.action = "OnMouseUp" And msg.id = 1 Then p_StartGame()

Else

Switch msg.action
Case "OnMouseOut":
Box(msg.x, msg.y, msg.width, msg.height, #BLACK)
Case "OnMouseOver":
Box(msg.x, msg.y, msg.width, msg.height, #RED)
Case "OnMouseUp":
p_CheckAnswer(msg.id - 1)
EndSwitch

EndIf

EndFunction

qloc = { {0, 1, 2, 3}, {1, 0, 2, 3}, {1, 2, 0, 3}, {3, 1, 2, 0} }
questions$ = {}
ques = {}

text$= {"",
"Willkommen zum Silviahemmet-Quiz V 0.1 Alpha",
"(c) 2015 Arnim Wolff",
"Kontaktadresse:",
"Malteser Krankenhaus St.Franziskus c/o Arnim Wolff",
"Station Silvia",
"Waldstraße 17",
"24939 Flensburg",
"0461/816-2340",
"Press LMB für Beginn - ESC für Ende",
"",
"Sende mir eine Postkarte wenn es Dir gefällt",
"oder neue Fragen einfallen oder",
"wen Du mir ein Geschenk machen willst",
"",
""}

OpenFile(1,"Questions.txt")

; load all questions into our array
While Not Eof(1)
questions$[q] = ReadLine(1)
q = q + 1
Wend

q = q - 1

CloseFile(1)

evtfunc = {OnMouseUp = p_EventFunc, OnMouseOver = p_EventFunc, OnMouseOut = p_EventFunc}

; show main menu
p_MainMenu()

; make buttons
MakeButton(1, #SIMPLEBUTTON, 0, 0, 320, 260, evtfunc)
MakeButton(2, #SIMPLEBUTTON, 6, 123, 627, 17, evtfunc)
MakeButton(3, #SIMPLEBUTTON, 6, 151, 627, 18, evtfunc)
MakeButton(4, #SIMPLEBUTTON, 6, 179, 627, 17, evtfunc)
MakeButton(5, #SIMPLEBUTTON, 6, 206, 627, 18, evtfunc)

; disable gaming buttons
For k = 2 To 5 Do DisableButton(k)

EscapeQuit(True)

; main loop!
Repeat
WaitEvent

Many thanks for your help ;)
User avatar
airsoftsoftwair
Posts: 5848
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: No Text refresh

Post by airsoftsoftwair »

If you change the display size and make it larger, you also need to adapt all other calls to functions which are related to the display size, i.e. all functions which draw something might need an adjustment in their position or size arguments.
Bugala
Posts: 1395
Joined: Sun Feb 14, 2010 7:11 pm

Re: No Text refresh

Post by Bugala »

Just giving example:

suppose you have hardcoded numbers, for example: (imaginary commands)

displaytext(200, 300) (- this would be x and y spot)


If this program is normally run on 800x600 screen, it means it would be about starting from about location 1/4th of screen from right, and be displayed starting from middle of screen from height point of view.

If you change display to 1920 x 1200 and still use these same x and y numbers on this command, it would now be displayed at about 1/10th from right and about 1/4th from top of screen from height point of view.

To make it look the same with 1920 x 1200 you would need to change the numbers into about:

displaytext(500, 600)


However, this would still not look the same, since yo would still need to change the font size, as if the font size would be, say 30, then 30x30 pixels in 800x600 is about 1/500th of the size of whole screen, while 30x30 in 1920 x 1200 is only rougly 1/3000th of a screens size.



When changing the numbers, you could use variables to define the position where to put them at.

For example, as i pointed out the 200,300 location with 800x600 would be about 1/4th and 1/2th (=middle), hence you could make it this way:

Screenwidth=1920
screenheight=1200

text_x = screenwidth/4
text_y = screenheight/2

textdisplay(text_x, text_y)

this way you would only need to change the screenwidth and screenheight variables, and text would always be displayed at same location (of 1/4th width, 1/2 = middle height), regardless of the screensize.
Post Reply