Turing program won't run; gives error message "Syntax error at 'loop'. expected 'end if'
Author |
Message |
programmerNeedsHelp2.0
|
Posted: Thu Jun 08, 2017 7:42 pm Post subject: Turing program won't run; gives error message "Syntax error at 'loop'. expected 'end if' |
|
|
Along with programmer_needs_help (my friend, who is also a member on compsci.ca), we are making a Turing game for our final school summative in Computer Science. I am currently programming a start screen which transitions to a main menu when the user presses "s" on the keyboard. The main menu contains four buttons. These four buttons include an "About Game" button, "Game Controls" button, "Start Game Button" and "Quit Game" button. When you click on the "About Game" button, it leads to a screen which talks about the game (a game overview.) Then, by clicking a "next arrow" on that screen, it leads to a second screen which continues on the description of the game overview. Then, once again, by clicking an arrow on this screen, it leads to the final screen that talks about the game overview. Now on each of these "game overview" screens, there is a button displaying "Back", in which when the user clicks it, it goes back to the main menu. When you click the "Game Controls" button on the main menu, it leads to a new screen, which obviously talks about game controls. Then, by clicking on the "back" button located on that screen, it leads back to the main menu. By clicking the "quit game" button, the execution window closes. I am not worrying too much about the "start game" button yet. Regardless of all this, the program is not running, and I believe that this is due to a mix up in my loops and if statements. Here is the code:
% Zaid Omer and Chabeshan Kandiah
% June 7th 2017
% SwordQuest.t
% Indicate Screen Size and Background Image
View.Set ("graphics,offscreenonly")
var window : int := Window.Open ("graphics:930;605,nobuttonbar")
% Indicate Variables
var swordQuestLogoImage : int
var forestBackground : int
const CENTREX : int := maxx div 2
const CENTREY : int := maxy div 2
var msSerifFont : int
var startOption : char
var pressSToStartPic : int
var pressSToStartSprite : int
var arrowInput : array char of boolean
var mainMenu : int
var levelOneBackground : int
var aboutGameButtonPic : int
var controlsButtonPic : int
var startButtonPic : int
var quitGameButtonPic : int
var aboutGameScreenOne : int
var aboutGameScreenTwo : int
var aboutGameScreenThree : int
var controlsScreen : int
var backButtonPic : int
% Import Start Screen Music
Music.PlayFileLoop ("StartOfGameSoundtrack.mp3")
% Start Screen
% Import Forest Background
forestBackground := Pic.FileNew ("StartScreenForestBackground.bmp")
forestBackground := Pic.Scale (forestBackground, 930, 605)
Pic.Draw (forestBackground, 0, 0, picMerge)
% Import Game Logo/Title
swordQuestLogoImage := Pic.FileNew ("SwordQuestLogo.bmp")
swordQuestLogoImage := Pic.Scale (swordQuestLogoImage, 430, 270)
Pic.Draw (swordQuestLogoImage, CENTREX - 220, CENTREY - 120, picMerge)
% Start Option
pressSToStartPic := Pic.FileNew ("pressSToStart.bmp")
pressSToStartPic := Pic.Scale (pressSToStartPic, 500, 200)
pressSToStartSprite := Sprite.New (pressSToStartPic)
Sprite.Show (pressSToStartSprite)
for startLocation : 0 .. 40
Sprite.SetPosition (pressSToStartSprite, CENTREX, startLocation - 25, true)
View.Update
delay (20)
end for
loop
startOption := getchar
if startOption = "s" or startOption = "S" then
Sprite.Hide (pressSToStartSprite)
cls
exit
end if
end loop
var playGame, aboutGame, exitAboutGame, exitAbout, gameControls, exitGameControls, menuDraw : boolean
var buttonX, buttonY, button : int
var buttonXOne, buttonYOne, buttonOne : int
var buttonXTwo, buttonYTwo, buttonTwo : int
var buttonXThree, buttonYThree, buttonThree : int
var buttonX1, buttonY1, button1 : int
loop
exitAboutGame := false
playGame := false
gameControls := false
exitGameControls := false
menuDraw := false
if menuDraw = false then
% Main Menu
mainMenu := Pic.FileNew ("mainMenu.bmp")
mainMenu := Pic.Scale (mainMenu, 930, 605)
Pic.Draw (mainMenu, 0, 0, picMerge)
% Create the pictures for main menu buttons
aboutGameButtonPic := Pic.FileNew ("aboutGameButtonPic.bmp")
Pic.Draw (aboutGameButtonPic, 8, 202, picMerge)
controlsButtonPic := Pic.FileNew ("controlsButtonPic.bmp")
Pic.Draw (controlsButtonPic, 319, 202, picMerge)
startButtonPic := Pic.FileNew ("startButtonPic.bmp")
Pic.Draw (startButtonPic, 630, 202, picMerge)
quitGameButtonPic := Pic.FileNew ("quitGameButtonPic.bmp")
Pic.Draw (quitGameButtonPic, 650, 20, picMerge)
menuDraw := true
end if
loop
mousewhere (buttonX, buttonY, button)
% In-game buttons
% Start Game Button
if (buttonX >= 631 and buttonX <= 919) and (buttonY >= 205 and buttonY <= 402) and button = 1 then
playGame := true
% Quit Game Button
elsif (buttonX >= 652 and buttonX <= 887) and (buttonY >= 21 and buttonY <= 70) and button = 1 then
Window.Close (window)
quit
% Game Controls Button
elsif (buttonX >= 321 and buttonX <= 611) and (buttonY >= 202 and buttonY <= 402) and button = 1 then
% Display "Game Controls" screen
Draw.Cls
View.Update
controlsScreen := Pic.FileNew ("controlsScreen.jpg")
controlsScreen := Pic.Scale (controlsScreen, 930, 605)
Pic.Draw (controlsScreen, 0, 0, picMerge)
loop
% Back Button in "Game Controls" screen
mousewhere (buttonX1, buttonY1, button1)
if (buttonX1 >= 602 and buttonX1 <= 640) and (buttonY >= 38 and buttonY <= 50) and button1 = 1 then
% Go back to main menu of game
exitAboutGame := true
menuDraw := false
% About Game Button
elsif (buttonX >= 8 and buttonX <= 300) and (buttonY >= 202 and buttonY <= 402) and button = 1 then
% Display "About Game" Screen One
Draw.Cls
View.Update
aboutGameScreenOne := Pic.FileNew ("aboutGameScreenOne.jpg")
aboutGameScreenOne := Pic.Scale (aboutGameScreenOne, 930, 605)
Pic.Draw (aboutGameScreenOne, 0, 0, picMerge)
loop
% "Back" Button in "About Game" Screen One
mousewhere (buttonXOne, buttonYOne, buttonOne)
if (buttonXOne >= 594 and buttonXOne <= 636) and (buttonYOne >= 98 and buttonYOne <= 111) and buttonOne = 1 then
% Go back to main menu of game
exitAboutGame := true
menuDraw := false
% Next Arrow in "About Game" Screen One
elsif (buttonXOne >= 489 and buttonXOne <= 510) and (buttonYOne >= 92 and buttonYOne <= 108) and buttonOne = 1 then
Draw.Cls
View.Update
aboutGameScreenTwo := Pic.FileNew ("aboutGameScreenTwo.jpg")
aboutGameScreenTwo := Pic.Scale (aboutGameScreenTwo, 930, 605)
Pic.Draw (aboutGameScreenTwo, 0, 0, picMerge)
loop
% "Back Button in "About Game" Screen Two
mousewhere (buttonXTwo, buttonYTwo, buttonTwo)
if (buttonXTwo >= 594 and buttonXTwo <= 636) and (buttonYTwo >= 98 and buttonYTwo <= 111) and buttonTwo = 1 then
% Go back to main menu of game
exitAboutGame := true
menuDraw := false
% Next Arrow in "About Game" Screen Two
elsif (buttonXTwo >= 489 and buttonXTwo <= 510) and (buttonYTwo >= 92 and buttonYTwo <= 108) and buttonTwo = 1 then
Draw.Cls
View.Update
aboutGameScreenThree := Pic.FileNew ("aboutGameScreenThree.jpg")
aboutGameScreenThree := Pic.Scale (aboutGameScreenThree, 930, 605)
Pic.Draw (aboutGameScreenThree, 0, 0, picMerge)
loop
% "Back Button in "About Game" Screen Three
mousewhere (buttonXThree, buttonYThree, buttonThree)
if (buttonXThree >= 594 and buttonXThree <= 636) and (buttonYThree >= 98 and buttonYThree <= 111) and buttonThree = 1 then
% Go back to main menu of game
exitAboutGame := true
menuDraw := false
end if
exit when exitAboutGame = true
end loop
exit when exitAboutGame = true
end if
exit when exitAboutGame = true
exit when playGame = true
end loop
exit when exitAboutGame = true
exit when playGame = true
end if
exit when exitAboutGame = true
exit when playGame = true
end loop
end if
exit when exitAboutGame = true
exit when playGame = true
end loop
end loop
Pls help!  |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Insectoid

|
Posted: Thu Jun 08, 2017 7:52 pm Post subject: RE:Turing program won\'t run; gives error message "Syntax error at \'loop\'. expected \'end if\' |
|
|
What do you think that error message is trying to tell you? |
|
|
|
|
 |
programmerNeedsHelp2.0
|
Posted: Thu Jun 08, 2017 8:02 pm Post subject: RE:Turing program won\'t run; gives error message "Syntax error at \'loop\'. expected \'end if\' |
|
|
Well, I know it's telling me to add an end if, instead of an end loop at the end. I've tried this, but it leads to further errors (i.e., expected end loop, etc.) When I tried all of Turing's suggestions, the program did eventually run, but certain buttons on the main menu did not function as they were supposed to (some buttons functioned, while some didn't). This also included buttons that were located on the instruction screen and game overview screen(s) |
|
|
|
|
 |
Insectoid

|
Posted: Thu Jun 08, 2017 8:06 pm Post subject: RE:Turing program won\'t run; gives error message "Syntax error at \'loop\'. expected \'end if\' |
|
|
One of your if statements does not have an end if. Turing can't possibly know where is supposed to be, because that requires knowing what you're trying to do. You need to figure out which end if it's missing and put it in the proper place. |
|
|
|
|
 |
programmerNeedsHelp2.0
|
Posted: Thu Jun 08, 2017 8:09 pm Post subject: RE:Turing program won\'t run; gives error message "Syntax error at \'loop\'. expected \'end if\' |
|
|
ok thanks |
|
|
|
|
 |
|
|