| My menu fails to exit 
 
	 
	
		| Author | Message |   
		| Legion 
 
 
 
 
 | 
			
				|  Posted: Thu May 01, 2014 7:40 pm    Post subject: My menu fails to exit |  |   
				| 
 |  
				| What is it you are trying to achieve? I want my menu to remain at the top of the screen and the game to exit the menu when the enemy is out of hp.
 
 
 What is the problem you are having?
 No matter what I do, it seems to be impossible to have the enemy die when he should and have the menu close as a result.
 
 Describe what you have tried to solve this problem
 I have tried rearranging the exit when.
 
 Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
 <Answer Here>
 
 
 	  | Turing: |  	  | 
proc attack
    if  spd >= eSpd then                                      %If your speed is greater than you will be prompted to attack first
        if  Rand.Int (1 , 100)  <= eEvas and  eEvas > style then
            %If a random number generated is less than the enemy's evasivness and their evasivness is greater than your style, the enemy dodges your attack
            put "The enemy avoided your attack!"
        else 
            eHealthPhy                                              %Enemy health calculations are made
            put "You heroically attack the enemy!"
            put "Enemy Health: ",  eHp
            Input.Pause
            Draw.Cls 
            bars
        end if
        put "Trooper is charging towards you!"
        if  Rand.Int (1 , 100)  <= evas and  evas > eStyle then
            %If a random number less than your evasivness is generated and your evasivness is greater than the enemy's style you dodge the attack
            put "You expertly evaded the enemy attack!"
        else 
            healthPhy
            put "Trooper bit you!"
            put "Health: ",  hp
            Input.Pause
            Draw.Cls 
            bars
            if  hp <= 0 then
                cls
                put "You have been slain by the Trooper!"
                Input.Pause
            end if
        end if
    else
        put "Trooper is charging towards you!"
        if  Rand.Int (1 , 100)  <= evas and  evas > eStyle then
            %%If a random number less than your evasivness is generated and your evasivness is greater than the enemy's style you dodge the attack
            put "You expertly evaded the enemy attack!"
        else 
            healthPhy
            put "Trooper bit you!"
            put "Health: ",  hp
            Input.Pause
            Draw.Cls 
            bars
            if  hp <= 0 then
                cls
                put "You have been slain by the Trooper!"
                Input.Pause
                Window.Close ( defWinID)
            end if
            if  Rand.Int (1 , 100)  <= eEvas and  eEvas > style then
                %If a random number generated is less than the enemy's evasivness and their evasivness is greater than your style, the enemy dodges your attack
                put "The enemy avoided your attack!"
            else 
                eHealthPhy
                put "You heroically attack the enemy!"
                put "Enemy Health: ",  eHp
                Input.Pause
                Draw.Cls 
                bars
                %exit when eHp <= 0
            end if
        end if
    end if
end  attack
proc  magic
    if  spd >= eSpd then                                     %If your speed is greater than you will be prompted to attack first
        if  Rand.Int (1 , 100)  <= eEvas and  eEvas > style then
            %If a random number generated is less than the enemy's evasivness and their evasivness is greater than your style, the enemy dodges your attack
            put "The enemy avoided your attack!"
        else 
            eHealthMag                                                %Enemy health calculations are made
            put "You blast the enemy with your magical powers!"
            put "Enemy Health: ",  eHp
            Input.Pause
            Draw.Cls 
            bars
            %exit when eHp <= 0
            Input.Pause
            put "Trooper is charging towards you!"
        end if
        if  Rand.Int (1 , 100)  <= evas and  evas > eStyle then
            %If a random number less than your evasivness is generated and your evasivness is greater than the enemy's style you dodge the attack
            put "You expertly evaded the enemy attack!"
        else 
            healthPhy
            put "Trooper bit you!"
            put "Health: ",  hp
            Input.Pause
            Draw.Cls 
            bars
            if  hp <= 0 then
                cls
                put "You have been slain by the Trooper!"
                Input.Pause
            end if
        end if
    else
        put "Trooper is charging towards you!"
        if  Rand.Int (1 , 100)  <= evas and  evas > eStyle then
            %%If a random number less than your evasivness is generated and your evasivness is greater than the enemy's style you dodge the attack
            put "You expertly evaded the enemy attack!"
        else 
            healthPhy
            put "Trooper bit you!"
            put "Health: ",  hp
            Input.Pause
            Draw.Cls 
            bars
            if  hp <= 0 then
                cls
                put "You have been slain by the Trooper!"
                Input.Pause
                Window.Close ( defWinID)
            end if
            if  Rand.Int (1 , 100)  <= eEvas and  eEvas > style then
                %If a random number generated is less than the enemy's evasivness and their evasivness is greater than your style, the enemy dodges your attack
                put "The enemy avoided your attack!"
            else 
                eHealthMag
                put "You blast the enemy with your magical powers!"
                put "Enemy Health: ",  eHp
                Input.Pause
                Draw.Cls 
                bars
                %exit when eHp <= 0
            end if
        end if
    end if
end  magic
proc  run
    if  spd *  evas >= eSpd *  eEvas then
        put "You succefully escaped!"
        Input.Pause
        cls
    else
        put "The Trooper is too fast for you!"
    end if
end  run
proc  fightMenu
    loop 
        first := GUI.CreateMenu ("Attack") 
        item (1) := GUI.CreateMenuItem ("Basic Attack",  attack) 
        item (2) := GUI.CreateMenuItem ("Double Slash",  doubleSlash) 
        item (3) := GUI.CreateMenuItem ("Stun Stab",  stunStab) 
        item (4) := GUI.CreateMenuItem ("Spirit Swipe",  spiritSwipe) 
        item (5) := GUI.CreateMenuItem ("Heart Rend ",  heartRend) 
        item (6) := GUI.CreateMenuItem ("Judgement",  judgement) 
        second := GUI.CreateMenu ("Magic") 
        item (7) := GUI.CreateMenuItem ("Basic Magic",  magic) 
        item (7) := GUI.CreateMenuItem ("Fire Ball",  fireball) 
        item (8) := GUI.CreateMenuItem ("Glaciate",  glaciate) 
        item (9) := GUI.CreateMenuItem ("Snapping Vines",  snappingVines) 
        item (10) := GUI.CreateMenuItem ("Earth's Embrace",  earthsEmbrace) 
        item (11) := GUI.CreateMenuItem ("Shatter the Sky",  shatterSky) 
        third := GUI.CreateMenu ("Other") 
        item (12) := GUI.CreateMenuItem ("Health Potion ",  healthPot) 
        item (13) := GUI.CreateMenuItem ("Mana Potion",  manaPot) 
        item (14) := GUI.CreateMenuItem ("Stamina Potion",  staminaPot) 
        item (15) := GUI.CreateMenuItem ("Run",  run)
        loop
            exit when GUI.ProcessEvent
        end loop
        exit when  eHp <= 0
        
    end loop
end  fightMenu
loop 
    bars
 
    fightMenu
end loop | 
 
 Please specify what version of Turing you are using
 4.1.1
 |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| Sponsor Sponsor
 
  
   |  |   
		|  |   
		| Insectoid 
 
  
 
 
 | 
			
				|  Posted: Thu May 01, 2014 8:02 pm    Post subject: RE:My menu fails to exit |  |   
				| 
 |  
				| Without seeing the bars function, I can't find anything wrong with this. It's possible that it is exiting, then skipping bars, then relaunching the fightMenu. |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| Tony 
 
  
 
 
 | 
			
				|  Posted: Thu May 01, 2014 8:08 pm    Post subject: RE:My menu fails to exit |  |   
				| 
 |  
				| 	  | code: |  	  | 
loop
 exit when GUI.ProcessEvent
 end loop
 exit when eHp <= 0
 
 | 
 The first loop doesn't exit until you click GUI.Quit button (which doesn't seem to exist in this example). So the program never gets to consider if eHp is 0 or not.
 |  
				|  Tony's programming blog. DWITE - a programming contest. |  |   
		|  |  |  
	  
		|  |   
		| Legion 
 
 
 
 
 | 
			
				|  Posted: Thu May 01, 2014 8:52 pm    Post subject: Re: RE:My menu fails to exit |  |   
				| 
 |  
				| Tony @ Thu May 01, 2014 8:08 pm wrote: 	  | code: |  	  | 
loop
 exit when GUI.ProcessEvent
 end loop
 exit when eHp <= 0
 
 | 
 The first loop doesn't exit until you click GUI.Quit button (which doesn't seem to exist in this example). So the program never gets to consider if eHp is 0 or not.
 Do I need to use a GUI.Quit button? Because I feel that would detract from the feel of the game. I tried to implement GUI.Quit some other way but it does not exit the menu until called again. I know what I'm missing is probably really obvious, it usually really is, but I need help.
 
 	  | Turing: |  	  | 
import GUI in "%oot/lib/GUI"
%Variables for the base stats and in game choices are declared, key gameplay
%elements are also established
var  atk, spd, prtct, matk, mprtct : real := 5
var  maxhp, maxmp, maxsp : real := 20
var  mp, sp, hp : real
var  evas, chrm, style : real := 1
var  eAtk, eSpd, ePrtct, eMatk, eMprtct : real := 3
var  eMaxhp : real := 20
var  eHp : real 
eHp :=  eMaxhp
var  eEvas, eStyle : real := 1
var  choice : string
var  charName, levelFont : int 
charName := Font.New ("Gulim:12") 
levelFont := Font.New ("Gulim:8")
View.Set ("nobuttonbar")
var  first, second, third, fourth, fifth, sixth : int             % The menus.
var  shift : int := 0
var  item : array 1 . . 20 of int         % The menu items.
var  name : array 1 . . 12 of string (20)
% Key procedures are written, they are critical to gameplay and host many
% important elements of the game.
proc  showStats
    put "Attack: ",  atk
    put "Protect: ",  prtct
    put "Health: ",  maxhp
    put "Stamina: ",  maxsp
    put "Mana ",  maxmp
    put "Magic Attack: ",  matk
    put "Magic Protect: ",  mprtct
    put "Speed: ",  spd
    put "Evasion: ",  evas
    put "Style: ",  style
    put "Charm: ",  chrm
 
    mp :=  maxmp
 
    sp :=  maxsp
 
    hp :=  maxhp
end  showStats
proc  bars
    drawfillbox (0 , 0 , 170 , 100 , 30)
    drawbox (0 , 0 , 170 , 100 , black)
    Font.Draw ("You", 10 , 80 , charName, black)
    Font.Draw ("LV: 1", 10 , 65 , levelFont, black)
    drawfillbox (0 , 60 , round (150 * ( hp / maxhp)), 40 , 12)
    drawbox (0 , 60 , 150 , 40 , black)
    drawfillbox (0 , 40 , round (150 * ( mp / maxmp)), 20 , 54)
    drawbox (0 , 40 , 150 , 20 , black)
    drawfillbox (0 , 20 , round (150 * ( sp / maxsp)), 0 , 120)
    drawbox (0 , 20 , 150 , 0 , black)
    drawfillbox (maxx , 60 , 466 , 0 , 30)
    drawbox (maxx , 60 , 466 , 0 , black)
    Font.Draw ("Enemy", 488 , 40 , charName, black)
    Font.Draw ("LV: 1", 488 , 25 , levelFont, black)
    drawfillbox (488 , 20 , round (150 * ( eHp / eMaxhp)  + 488), 0 , 12)
    drawbox (488 , 0 , 638 , 20 , black)
end  bars
proc  emptyBars
    drawfillbox (0 , 60 , round (150 * ( hp / maxhp)), 40 , 12)
    drawbox (0 , 60 , 150 , 40 , black)
    drawfillbox (0 , 40 , round (150 * ( mp / maxmp)), 20 , 54)
    drawbox (0 , 40 , 150 , 20 , black)
    drawfillbox (0 , 20 , round (150 * ( sp / maxsp)), 0 , 120)
    drawbox (0 , 20 , 150 , 0 , black)
    drawbox (488 , 0 , 638 , 20 , black)
end  emptyBars
proc  eHealthPhy
 
    eHp :=  eHp - round ( atk * 3  / ePrtct)
end  eHealthPhy
proc  healthPhy
 
    hp :=  hp - round ( eAtk * 2  / prtct)
end  healthPhy
proc  eHealthMag
 
    eHp :=  eHp - round ( matk * 3  / eMprtct)
end  eHealthMag
proc  healthMag
 
    hp :=  hp - round ( eMatk * 2  / mprtct)
end  healthMag
proc  attack
    if  spd >= eSpd then                                      %If your speed is greater than you will be prompted to attack first
        if  Rand.Int (1 , 100)  <= eEvas and  eEvas > style then
            %If a random number generated is less than the enemy's evasivness and their evasivness is greater than your style, the enemy dodges your attack
            put "The enemy avoided your attack!"
        else 
            eHealthPhy                                              %Enemy health calculations are made
            put "You heroically attack the enemy!"
            put "Enemy Health: ",  eHp
            Input.Pause
            Draw.Cls 
            bars
        end if
        put "Trooper is charging towards you!"
        if  Rand.Int (1 , 100)  <= evas and  evas > eStyle then
            %If a random number less than your evasivness is generated and your evasivness is greater than the enemy's style you dodge the attack
            put "You expertly evaded the enemy attack!"
        else 
            healthPhy
            put "Trooper bit you!"
            put "Health: ",  hp
            Input.Pause
            Draw.Cls 
            bars
            if  hp <= 0 then
                cls
                put "You have been slain by the Trooper!"
                Input.Pause
            end if
        end if
    else
        put "Trooper is charging towards you!"
        if  Rand.Int (1 , 100)  <= evas and  evas > eStyle then
            %If a random number less than your evasivness is generated and your evasivness is greater than the enemy's style you dodge the attack
            put "You expertly evaded the enemy attack!"
        else 
            healthPhy
            put "Trooper bit you!"
            put "Health: ",  hp
            Input.Pause
            Draw.Cls 
            bars
            if  hp <= 0 then
                cls
                put "You have been slain by the Trooper!"
                Input.Pause
                Window.Close ( defWinID)
            end if
            if  Rand.Int (1 , 100)  <= eEvas and  eEvas > style then
                %If a random number generated is less than the enemy's evasivness and their evasivness is greater than your style, the enemy dodges your attack
                put "The enemy avoided your attack!"
            else 
                eHealthPhy
                put "You heroically attack the enemy!"
                put "Enemy Health: ",  eHp
                Input.Pause
                Draw.Cls 
                bars
                %exit when eHp <= 0
            end if
        end if
    end if
end  attack
proc  magic
    if  spd >= eSpd then                                     %If your speed is greater than you will be prompted to attack first
        if  Rand.Int (1 , 100)  <= eEvas and  eEvas > style then
            %If a random number generated is less than the enemy's evasivness and their evasivness is greater than your style, the enemy dodges your attack
            put "The enemy avoided your attack!"
        else 
            eHealthMag                                                %Enemy health calculations are made
            put "You blast the enemy with your magical powers!"
            put "Enemy Health: ",  eHp
            Input.Pause
            Draw.Cls 
            bars
            %exit when eHp <= 0
            Input.Pause
            put "Trooper is charging towards you!"
        end if
        if  Rand.Int (1 , 100)  <= evas and  evas > eStyle then
            %If a random number less than your evasivness is generated and your evasivness is greater than the enemy's style you dodge the attack
            put "You expertly evaded the enemy attack!"
        else 
            healthPhy
            put "Trooper bit you!"
            put "Health: ",  hp
            Input.Pause
            Draw.Cls 
            bars
            if  hp <= 0 then
                cls
                put "You have been slain by the Trooper!"
                Input.Pause
            end if
        end if
    else
        put "Trooper is charging towards you!"
        if  Rand.Int (1 , 100)  <= evas and  evas > eStyle then
            %%If a random number less than your evasivness is generated and your evasivness is greater than the enemy's style you dodge the attack
            put "You expertly evaded the enemy attack!"
        else 
            healthPhy
            put "Trooper bit you!"
            put "Health: ",  hp
            Input.Pause
            Draw.Cls 
            bars
            if  hp <= 0 then
                cls
                put "You have been slain by the Trooper!"
                Input.Pause
                Window.Close ( defWinID)
            end if
            if  Rand.Int (1 , 100)  <= eEvas and  eEvas > style then
                %If a random number generated is less than the enemy's evasivness and their evasivness is greater than your style, the enemy dodges your attack
                put "The enemy avoided your attack!"
            else 
                eHealthMag
                put "You blast the enemy with your magical powers!"
                put "Enemy Health: ",  eHp
                Input.Pause
                Draw.Cls 
                bars
                %exit when eHp <= 0
            end if
        end if
    end if
end  magic
proc  run
    if  spd *  evas >= eSpd *  eEvas then
        put "You succefully escaped!"
        Input.Pause
        cls
    else
        put "The Trooper is too fast for you!"
    end if
end  run
proc  doubleSlash
 
    atk :=  atk * 2 
    attack
 
    atk :=  atk / 2
end  doubleSlash
proc  stunStab
 
    atk :=  atk * 1 .5 
    attack
 
    atk :=  atk / 1 .5 
    eSpd :=  -eSpd
end  stunStab
proc  spiritSwipe
 
    atk :=  atk * ( matk * 2) 
    attack
 
    atk :=  atk / ( matk * 2)
end  spiritSwipe
proc  heartRend
 
    atk :=  atk * 3 .5 
    attack
 
    atk :=  atk / 3 .5
end  heartRend
proc  judgement
 
    atk :=  atk * 5 .5 
    attack
 
    atk :=  atk / 5 .5
end  judgement
proc  fireball
 
    matk :=  matk * 1 .9 
    magic
 
    matk :=  matk / 1 .9
end  fireball
proc  glaciate
 
    matk :=  matk * 1 .9 
    magic
 
    matk :=  matk / 1 .9 
    eSpd :=  eSpd * 0 .8
end  glaciate
proc  snappingVines
 
    matk :=  matk * 1 .9 
    magic
 
    matk :=  matk / 1 .9 
    eSpd := 0 
    eEvas := 0
end  snappingVines
proc  earthsEmbrace
 
    matk :=  matk * 3 .5 
    magic
 
    matk :=  matk / 3 .5 
    eSpd := 0 
    eEvas := 0
end  earthsEmbrace
proc  shatterSky
 
    matk :=  matk * 5 .5 
    magic
 
    matk :=  matk / 5 .5
end  shatterSky
proc  healthPot
 
    hp :=  hp + maxhp * 0 .25
    if  hp > maxhp then 
        hp :=  maxhp
    end if 
    bars
end  healthPot
proc  manaPot
 
    mp :=  mp + maxmp * 0 .25
    if  mp > maxmp then 
        mp :=  maxmp
    end if 
    bars
end  manaPot
proc  staminaPot
 
    sp :=  sp + maxsp * 0 .25
    if  sp > maxsp then 
        sp :=  maxsp
    end if 
    bars
end  staminaPot
proc  fightMenu
    loop 
        first := GUI.CreateMenu ("Attack") 
        item (1) := GUI.CreateMenuItem ("Basic Attack",  attack) 
        item (2) := GUI.CreateMenuItem ("Double Slash",  doubleSlash) 
        item (3) := GUI.CreateMenuItem ("Stun Stab",  stunStab) 
        item (4) := GUI.CreateMenuItem ("Spirit Swipe",  spiritSwipe) 
        item (5) := GUI.CreateMenuItem ("Heart Rend ",  heartRend) 
        item (6) := GUI.CreateMenuItem ("Judgement",  judgement) 
        second := GUI.CreateMenu ("Magic") 
        item (7) := GUI.CreateMenuItem ("Basic Magic",  magic) 
        item (7) := GUI.CreateMenuItem ("Fire Ball",  fireball) 
        item (8) := GUI.CreateMenuItem ("Glaciate",  glaciate) 
        item (9) := GUI.CreateMenuItem ("Snapping Vines",  snappingVines) 
        item (10) := GUI.CreateMenuItem ("Earth's Embrace",  earthsEmbrace) 
        item (11) := GUI.CreateMenuItem ("Shatter the Sky",  shatterSky) 
        third := GUI.CreateMenu ("Other") 
        item (12) := GUI.CreateMenuItem ("Health Potion ",  healthPot) 
        item (13) := GUI.CreateMenuItem ("Mana Potion",  manaPot) 
        item (14) := GUI.CreateMenuItem ("Stamina Potion",  staminaPot) 
        item (15) := GUI.CreateMenuItem ("Run",  run)
        if  eHp <= 0 then
            GUI.Quit
        end if
        loop
            exit when GUI.ProcessEvent
        end loop
    end loop
end  fightMenu
%The user is prompted to pick their class, this determines what benefits they
%will gain
put "Pick your class"
put "Warrior, strong and sturdy."
put "Mage, inclined to magic."
put "Ranger, nimble and deadly."
get  choice
if  choice = "warrior" then                                   %Stat multipliers for each class adds an element of choice to selecting a class 
    atk :=  atk * 1 .6 
    prtct :=  prtct * 2 
    maxhp :=  maxhp * 2 
    maxsp :=  maxsp * 1 
    maxmp :=  maxmp * 0 .4 
    matk :=  matk * 0 .6 
    mprtct :=  mprtct * 2 
    spd :=  spd * 0 .4 
    evas :=  evas * 0 
    style :=  style * 0 .4 
    chrm :=  chrm * 1 
    showStats
elsif  choice = "ranger" then 
    atk :=  atk * 2 .2 
    prtct :=  prtct * 0 .2 
    maxhp :=  maxhp * 0 .8 
    maxsp :=  maxsp * 1 .4 
    maxmp :=  maxmp * 0 .2 
    matk :=  matk * 0 .2 
    mprtct :=  mprtct * 0 .2 
    spd :=  spd * 2 .2 
    evas :=  evas * 1 .6 
    style :=  style * 1 .6 
    chrm :=  chrm * 1 
    showStats
elsif  choice = "mage" then 
    atk :=  atk * 0 .2 
    prtct :=  prtct * 0 .2 
    maxhp :=  maxhp * 0 .8 
    maxsp :=  maxsp * 0 .2 
    maxmp :=  maxmp * 1 .6 
    matk :=  matk * 2 .4 
    mprtct :=  mprtct * 2 .2 
    spd :=  spd * 1 
    evas :=  evas * 1 
    style :=  style * 1 
    chrm :=  chrm * 1 
    showStats
end if
Input.Pause
cls
loop 
    bars
 
    fightMenu
end loop | 
 |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| Tony 
 
  
 
 
 | 
			
				|  Posted: Thu May 01, 2014 10:56 pm    Post subject: RE:My menu fails to exit |  |   
				| 
 |  
				| You just need to actually exit that loop. Previously it could be shown that you've had an infinite loop that never exited. You could do something like 
 	  | code: |  	  | 
loop
 exit when GUI.ProcessEvent or eHp <= 0
 end loop
 
 | 
 |  
				|  Tony's programming blog. DWITE - a programming contest. |  |   
		|  |  |  
	  
		|  |   
		|  |  
 |