I am writing a quiz style app that involves displaying a lot of different text at different times.
I have included most of the current code below. The basic issue is that I have different states [DrawQuestion/DrawAnswerResult] being the two currently worked on.
I start in the DrawQuestion state and this works fine. When the user clicks the submit button then I switch the state to DrawAnswerResult and call hide_question_screen() which sets the current text to not visible and deletes those text objects. After this the program correctly is calling the draw_answer_result function, but it still continues to display the question text that I have tried to remove from the screen.
No idea what I'm doing wrong here.
// Project: HelloWorld
// Created: 2016-02-09
// #option_explicit
#include "strings.agc"
#include "questions.agc"
#constant DrawLoginMenu 1
#constant DrawMainMenu 2
#constant DrawQuestion 3
#constant DrawAnswerResult 4
// set window properties
SetWindowTitle( "HelloWorld" )
SetWindowSize( 1024, 768, 0 )
// set display properties
SetOrientationAllowed( 1, 1, 1, 1 )
LoadImage ( 1, "button_down.png" )
LoadImage( 2, "button.png" )
deviceWidth = GetMaxDeviceWidth()
global submit_button = 1
AddVirtualButton( submit_button, 50, 90, 10 )
SetVirtualButtonVisible(submit_button,1)
CreateEditBox(1)
SetEditBoxSize( 1, 50, 10 )
SetEditBoxPosition( 1, 50 - GetEditBoxWidth(1)/2, 75 )
setup_addition()
global current_question = 0
current_question = Random(0,questions.length)
global current_answer$ = ""
global state = DrawQuestion
do
select state
case DrawQuestion
draw_question()
endcase
case DrawAnswerResult
draw_answer_result()
endcase
endselect
Sync()
loop
function draw_question()
SetVirtualButtonImageUp( submit_button, 2 )
If GetVirtualButtonState(1)=1
current_answer$ = GetEditBoxText(1)
current_answer_num# = Val(current_answer$)
Print("Button Down")
SetVirtualButtonImageDown( submit_button, 1 )
If current_answer$ <> ""
hide_question_screen()
DrawBox( 0, 0, 100, 100, 0, 0, 0, 0, 1 )
state = DrawAnswerResult
exitfunction
Elseif current_answer_num# = Val(questions[current_question].Solution) //+ Val(aquestion.Terms[1])
Print("Good Job")
Else
Print("You are a loser")
Print(current_answer$)
Print("You are a loser")
EndIf
EndIf
display_addition(current_question)
endfunction
current_question = Random(0,questions.length)
function draw_answer_result()
Print("called")
Print(state)
endfunction
TYPE QuestionType
ProblemType AS STRING
Solution AS STRING
Terms AS STRING[2]
ENDTYPE
Global questions as QuestionType[]
function setup_addition ()
Global fileArray as String[]
fileReadID = OpenToRead( "addition.csv")
tmpArray$ as String[]
i = 1
while fileEOF(fileReadID) <> 1
r$=Readline(fileReadID) //Info
tmpArray$ = split(r$, ",")
if(tmpArray$.length > 0) and i > 1
question as QuestionType
question.ProblemType = tmpArray$[0]
question.Solution = tmpArray$[1]
for idx = 2 to tmpArray$.length
question.Terms[idx-2] = (tmpArray$[idx])
next idx
questions.insert(question)
fileArray.insert(r$)
endif
i = i + 1
endwhile
CloseFile(fileReadID)
endfunction
global term1
global term2
function display_addition(q_index)
term1 = CreateText(questions[q_index].Terms[0])
SetTextSize ( term1, 12 )
SetTextPosition(term1, 50 - GetTextTotalWidth(term1), 10)
term2 = CreateText("+" + questions[q_index].Terms[1])
SetTextSize ( term2, 12 )
SetTextPosition(term2, 50 - GetTextTotalWidth(term2), 40)
endfunction
function hide_question_screen()
SetTextVisible( term1, 0 )
SetTextVisible( term2, 0 )
DeleteText(term1)
DeleteText(term2)
endfunction