Computer Science Canada

Buttons not getting input + flickering?

Author:  Pyralblitzzz [ Fri Nov 02, 2012 11:05 am ]
Post subject:  Buttons not getting input + flickering?

What is it you are trying to achieve?
I am trying to create a Final Fantasy style RPG and ran into a problem with the battle procedure.


What is the problem you are having?
I had it working with "get", but thought that it would be nicer with buttons. When I added them, the screen started flickering, and the buttons don't actually get clicked; clicking them just pauses the flickering. (Yes, I am using View.UpdateArea)

Describe what you have tried to solve this problem
The View.Update functions, reviewing the Turing Tutorial on buttons and widgets.


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Here is the program
Turing:


import GUI
View.Set ("graphics:max;max,offscreenonly,nobuttonbar,title:Battle Test")
var dmg1,dmg2,hp1,hp2,atk1,def1,mag1,magdef1,atk2,def2,mag2,magdef2,lck1,lck2,spellgen: int
var atkbut1,atkbut2,defbut1,defbut2,magbut1,magbut2 : int
var act1,act2: boolean
var spell1, spell2 : string
hp1 := 500
hp2 := 500
atk1 := 12
atk2 := 30
def1 := 15
def2 := 30
mag1 := 52
mag2 := 2
magdef1 := 30
magdef2 := 5
lck1 := 13
lck2 := 23
spell1 := "Potatoes"
spell2 := "Potatoes"
act1 := false
act2 := false
%Physical attacks
proc attack1
    dmg1 := atk1 - def2 + Rand.Int (0,lck1)
    act1 := true
end attack1

proc attack2
    dmg2 := atk2 - def1 + Rand.Int (0,lck2)
    act2 := true
end attack2
%Restorative spells
proc heal1
    hp1 := hp1 + mag1 + Rand.Int (0,lck1)
    act1 := true
end heal1

proc heal2
    hp2 := hp2 + mag2 + Rand.Int (0,lck2)
    act2 := true
end heal2
%Magic stuff
proc magic1
    spellgen := Rand.Int (0,5)
    if spellgen = 1 then
        spell1 := "FIRAGA"
    elsif spellgen = 2 then
        spell1 := "BLIZZAGA"
    elsif spellgen = 3 then
        spell1 := "THUNDAGA"
    elsif spellgen = 4 then
        spell1 := "CURAGA"
    end if
    if spell1 not= "CURAGA" then
        dmg1 := mag1 - magdef2 + Rand.Int (0,lck1)
    else heal1
    end if
    act1 := true
end magic1

proc magic2
    spellgen := Rand.Int (0,5)
    if spellgen = 1 then
        spell2 := "FIRAGA"
    elsif spellgen = 2 then
        spell2 := "BLIZZAGA"
    elsif spellgen = 3 then
        spell2 := "THUNDAGA"
    elsif spellgen = 4 then
        spell2 := "CURAGA"
    end if
    if spell2 not= "CURAGA" then
        dmg2 := mag2 - magdef1 + Rand.Int (0,lck2)
    else heal2
    end if
    act2 := true
end magic2
%defending
proc defend1
    def1 := def1 * 2
    act1 := true
end defend1

proc defend2
    def2 := def2 * 2
    act2 := true
end defend2
%main battle loop
proc battle
    loop
        atkbut1 :=GUI.CreateButton (400,200,20, "Attack", attack1)
        View.UpdateArea (0,0,maxx,maxy)
        atkbut2 :=GUI.CreateButton (700,200,20, "Attack", attack2)
        View.UpdateArea (0,0,maxx,maxy)
        defbut1 :=GUI.CreateButton (400,100,20, "Defend", defend1)
        View.UpdateArea (0,0,maxx,maxy)
        defbut2 :=GUI.CreateButton (700,100,20, "Defend", defend2)
        View.UpdateArea (0,0,maxx,maxy)
        magbut1 :=GUI.CreateButton (400,150,20, "Magic", magic1)
        View.UpdateArea (0,0,maxx,maxy)
        magbut2 :=GUI.CreateButton (700,150,20, "Magic", magic2)
        View.UpdateArea (0,0,maxx,maxy)
        exit when GUI.ProcessEvent
        dmg1 := 0
        dmg2 := 0
        cls
        View.UpdateArea (0,0,maxx,maxy)
        if hp1 > 500 then
            hp1 := 500
        end if
        if hp2 > 500 then
            hp2 := 500
        end if
        def1 := 15
        def2 := 30
        Draw.FillOval (400,400,10,10,black)
        Draw.FillOval (700,400,10,10,black)
        locatexy (400,300)
        put hp1
        View.UpdateArea (0,0,maxx,maxy)
        locatexy (700,300)
        put hp2
        View.UpdateArea (0,0,maxx,maxy)
        put "What will you do?"
        if act1 = true and act2 = true then
            hp1 := hp1-dmg2
            hp2 := hp2-dmg1
            act1 := false
            act2 := false
        end if
        delay (20)
    end loop           
end battle           
battle




Please specify what version of Turing you are using
4.1

Author:  Aange10 [ Fri Nov 02, 2012 11:51 am ]
Post subject:  RE:Buttons not getting input + flickering?

Quote:
When I added them, the screen started flickering, and the buttons don't actually get clicked; clicking them just pauses the flickering. (Yes, I am using View.UpdateArea)


The problem is your using View.UpdateArea incorrectly. Look at the difference between these two programs:


Turing:

View.Set ("offscreenonly")
var x, y : int := 15
loop
    cls
    drawfilloval (x, y, 10, 10, red)
    View.UpdateArea(0,0,maxx,maxy)
    drawfilloval (x, y + 15, 10, 10, red)
    View.UpdateArea(0,0,maxx,maxy)
    drawfilloval (x, y + 30, 10, 10, red)
    View.UpdateArea(0,0,maxx,maxy)
    drawfilloval (x, y + 45, 10, 10, red)
    View.UpdateArea(0,0,maxx,maxy)
    drawfilloval (x, y + 60, 10, 10, red)
    View.UpdateArea(0,0,maxx,maxy)
    drawfilloval (x, y + 75, 10, 10, red)
    View.UpdateArea(0,0,maxx,maxy)
    drawfilloval (x, y + 90, 10, 10, red)
    View.UpdateArea(0,0,maxx,maxy)
   
    x += 1
    if x >= maxx then
        x := 15
    end if
    View.UpdateArea(0,0,maxx,maxy)
end loop


Turing:

View.Set ("offscreenonly")
var x, y : int := 15
loop
    cls
    drawfilloval (x, y, 10, 10, red)
    drawfilloval (x, y + 15, 10, 10, red)
    drawfilloval (x, y + 30, 10, 10, red)
    drawfilloval (x, y + 45, 10, 10, red)
    drawfilloval (x, y + 60, 10, 10, red)
    drawfilloval (x, y + 75, 10, 10, red)
    drawfilloval (x, y + 90, 10, 10, red)
   
    x += 1
    if x >= maxx then
        x := 15
    end if
    View.UpdateArea(0,0,maxx,maxy)
end loop

Author:  Insectoid [ Fri Nov 02, 2012 12:19 pm ]
Post subject:  RE:Buttons not getting input + flickering?

Your buttons are not working because you create them in a loop. You're effectively stacking hundreds of buttons on top of each other.

Author:  Pyralblitzzz [ Fri Nov 02, 2012 2:42 pm ]
Post subject:  Re: Buttons not getting input + flickering?

Okay, I did both of those things, but now it just flickers a bit less, and the buttons are gone altogether.

Author:  chipanpriest [ Fri Nov 02, 2012 7:19 pm ]
Post subject:  Re: Buttons not getting input + flickering?

Why use buttons? This is what I do:

Turing:

Draw.FillBox (100,100,200,200,red)
loop
mousewhere (mx,my,click)
if mx >= 100 and mx <= 200 and my >= 100 and my <= 200 and click = 1 then
%do whatever
exit
end if
end loop

Author:  Aange10 [ Fri Nov 02, 2012 9:54 pm ]
Post subject:  Re: Buttons not getting input + flickering?

chipanpriest @ 2/11/2012, 6:19 pm wrote:
Why use buttons? This is what I do:

Turing:

Draw.FillBox (100,100,200,200,red)
loop
mousewhere (mx,my,click)
if mx >= 100 and mx <= 200 and my >= 100 and my <= 200 and click = 1 then
%do whatever
exit
end if
end loop


I have to agree, this is what I do aswell. I reinvented the wheel and made my own modules simply because I've heard so many terrible things about the Turing GUI that I never wanted to use it. Although honestly, I don't think it's too bad.

Author:  evildaddy911 [ Tue Nov 06, 2012 5:30 pm ]
Post subject:  RE:Buttons not getting input + flickering?

same here. The turing GUI modules are built for use without the offscreenonly. while my GUI classes aren't as polished looking, they are much more customizable and easier to use.

however, if you don't want to make button classes/modules, use the GUI.show and GUI.hide procedures to display youre buttons.
EG:
code:

var btn1 : int := /* initialization */
var btn2 : int := /* initialization */

proc battle
GUI.Show(btn1)
/*
battle
*/
GUI.Hide(btn1)
end battle

proc other_action
GUI.Show(btn2)
/*
action
*/
GUI.Hide(btn2)
end other_action


: