Original Post
I''m having a small error with the GUI in Turing. I''m making a Jeopardy game. Here''s the code:
type question :
record
proposition : string
first_word : string
answer : string
end record
var choice : int
procedure do_widget
choice := GUI.GetEventWidgetID
end do_widget
procedure round_one
var input : string (1)
var category : array 1 .. 6 of string
category (1) := "Math"
category (2) := "Science"
category (3) := "History"
category (4) := "Toronto"
category (5) := "Ends With ''y''"
category (6) := "Food"
var size : int := sizeof (question)
var round_question : array 1 .. 6, 1 .. 5 of question
var question_stream : int
open : question_stream, "record_round_one.dat", read, seek
assert question_stream > 0
for category_chosen : 1 .. 6
for question_chosen : 1 .. 5
var rand_num : int
randint (rand_num, 1, 4)
seek : question_stream, size * (rand_num + 4 * (question_chosen - 1) + 20 * (category_chosen - 1) - 1)
read : question_stream, round_question (category_chosen, question_chosen)
end for
end for
close : question_stream
var exists : array 1 .. 6, 1 .. 5 of boolean
for button_column : 1 .. 6
for button_value : 1 .. 5
exists (button_column, button_value) := true
end for
end for
loop
colourback (blue)
cls
var array_button : array 1 .. 6, 1 .. 5 of int
for button_column : 1 .. 6
for button_value : 1 .. 5
if exists (button_column, button_value) then
array_button (button_column, button_value) := GUI.CreateButton (round ((button_column - 1) / 6 * maxx), maxy - round (button_value / 6 * maxy + maxy div 12), round (maxx div 6),
"$" +
intstr (100 * button_value), do_widget)
end if
end for
end for
var chosen_column, chosen_row : int
loop
choice := 0
chosen_column := 0
chosen_row := 0
exit when GUI.ProcessEvent
var done : boolean := false
if choice > 0 then
for button_column : 1 .. 6
for button_value : 1 .. 5
if exists (button_column, button_value) then
if array_button (button_column, button_value) = choice then
chosen_column := button_column
chosen_row := button_value
done := true
exit
end if
end if
end for
exit when done
end for
end if
exit when done
end loop
exists (chosen_column, chosen_row) := false
GUI.Dispose (array_button (chosen_column, chosen_row))
end loop
end round_one
The problem is that I''m trying to make a button disappear one you press it. It works for the first but not for subsequent buttons. The loop will not exit for later presses even though a WidgetID is read. Why would this work?