0
我是IDL的新手,並且作爲一種學習方式,我嘗試創建一個猜數字遊戲。我有一個有三個按鈕的小工具:一個告訴程序你正在考慮的數字大於計算機詢問的數字,一個小於一個,另一個正確。IDL:Button Widget在一次推送後停止更新
我的問題是,一旦你按下了,即更大的按鈕,如果你再次按下它,它不會做任何事情。例如。程序開始猜測500,如果我按大一點,它猜測750.如果我現在再次按大,程序不響應。
我的代碼是這樣的:
PRO test1_event, ev
WIDGET_CONTROL, ev.top, GET_UVALUE = stash
minimum = 0
maximum = 1000
IF (ev.Id EQ largerbutton) THEN BEGIN
minimum = (minimum+maximum)/2
maximum = maximum
ENDIF
IF (ev.Id EQ smallerbutton) THEN BEGIN
maximum = (minimum+maximum)/2
minimum = minimum
ENDIF
IF (ev.Id EQ correctbutton) THEN BEGIN
help2 = string('I got it!') ;This prints to a text widget
ENDIF
END
PRO test1
wBase = WIDGET_BASE(X_SCROLL_SIZE = 512, Y_SCROLL_SIZE = 512)
;wDraw = WIDGET_WINDOW(wBase, X_SCROLL_SIZE = 512, Y_SCROLL_SIZE = 512)
Lower = WIDGET_BUTTON(wBase, VALUE = 'Smaller', XOFFSET = 60, YOFFSET = 250)
Higher = WIDGET_BUTTON(wBase, VALUE = 'Larger', XOFFSET = 225, YOFFSET = 250)
Correct = WIDGET_BUTTON(wBase, VALUE = 'Correct', XOFFSET = 380, YOFFSET = 250)
minimum = 0
maximum = 1000
help1 = string('Please think of a number between' + string(minimum) + ' and ' + string(maximum))
help2 = string('Is your number ' + string((minimum + maximum)/2) + '?')
wText = WIDGET_TEXT(wBase, VALUE = ['Welcome to my little game. I will now try and guess a number you are thinking of.'], XSIZE = 63,XOFFSET = 50, YOFFSET = 100)
wText1 = WIDGET_TEXT(wBase, VALUE = help1, XSIZE = 63,XOFFSET = 50, YOFFSET = 120)
wText2 = WIDGET_TEXT(wBase, VALUE = help2, XSIZE = 63,XOFFSET = 50, YOFFSET = 140)
stash = {text1:wText, text2:wText1, text3:wText2, $
lower:Lower, higher:Higher, correct:Correct, minimum:minimum, maximum:maximum}
WIDGET_CONTROL, wBase, SET_UVALUE = stash, /REALIZE
XMANAGER, 'test1', wBase
end
我一直在使用一個while循環,也REPEAT想說,但如果我按大按鈕和0,如果我按計劃只是去一直到999更小。
任何想法,我可以做什麼?
編輯:添加程序
它看起來像你缺少一些你的代碼。在「藏匿」中存儲「大按鈕」和「小按鈕」嗎?你打電話給XMANAGER開始事件處理嗎?最後,你如何存儲「最小」和「最大」?請發佈您的整個程序。 –
感謝您的反饋,添加了程序的其餘部分。 – sCuper