Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Exiting this loop...
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
horlickiki




PostPosted: Fri Mar 18, 2005 7:12 pm   Post subject: Exiting this loop...

Quote:



setscreen ("graphics:640;400")
var y : int %%%%%%%%%%%%%%%%%%% temp?

%VARIABLE DECLARATION / ARRAY DECLARATION

var fonta := Font.New ("Amerigo BT:36")
var fontb := Font.New ("Amerigo BT:24")
var fontc := Font.New ("Amerigo BT:18")
var fontd := Font.New ("Amerigo BT:14")
var fontcountdown := Font.New ("Amerigo BT:144")

var ctc : string (1)
var movex : string (1)

var mmptxchoice : int
var modechoiceptx : int
var countdown : int := 3
var move : int := 305

var mmptxoption : flexible array 1 .. 3 of string
var modeptx : flexible array 1 .. 3 of string

mmptxoption (1) := "1. Play"
mmptxoption (2) := "2. View Instructions"
mmptxoption (3) := "3. Exit"
modeptx (1) := "1. 1 Player"
modeptx (2) := "2. 2 Players"
modeptx (3) := "3. Exit"

% PROCEDURE DECLARATION / PROCESS DECLARATION

proc X
Font.Draw ("Nobody Is Winning", 220, 100, fontc, 0)
loop
Font.Draw ("X", move, 200, fontb, 0)
drawline (315, 180, 315, 240, 0)
%drawline (0, 210, 305, 210, 0)
%drawline (335, 210, 640, 210, 0)
if hasch then
getch (movex)
if movex = "S" or movex = "s" then
move -= 10
Font.Draw ("X", move + 10, 200, fontb, 7)
elsif movex = "J" or movex = "j" then
move += 10
Font.Draw ("X", move - 10, 200, fontb, 7)
end if
cls
if move < 305 then
Font.Draw ("Player 1 Is Winning", 220, 100, fontc, 0)
elsif move > 305 then
Font.Draw ("Player 2 Is Winning", 220, 100, fontc, 0)
else
Font.Draw ("Nobody Is Winning", 220, 100, fontc, 0)
exit when move = 0 or move = maxx
end if
end if

end loop
end X
proc player1ptx
cls
Font.Draw ("Get Ready...", 220, 300, fontb, 0)
Font.Draw ("Press Any Key To Start The Countdown", 150, 100, fontd, 0)
locatexy (310, 50)
getch (ctc)
cls
for q : 1 .. 3
Font.Draw (intstr (countdown), 250, 150, fontcountdown, 0)
%locatexy (310, 50)
%put countdown
countdown := countdown - 1
delay (1000)
cls
end for
Font.Draw ("Go!!!", 120, 120, fontcountdown, 0)
delay (1000)
cls
X
end player1ptx

proc rtmm
cls
Font.Draw ("That Was Not An Option:", 85, 300, fontb, 0)
Font.Draw ("Redirecting To main menu", 85, 200, fontb, 0)
delay (600)
Font.Draw (".", 460, 200, fontb, 0)
delay (600)
Font.Draw (".", 470, 200, fontb, 0)
delay (600)
Font.Draw (".", 480, 200, fontb, 0)
delay (600)
end rtmm

%WELCOME MENU
color (0)
colorback (black)
cls
Font.Draw ("Welcome To Pull The X", 60, 300, fonta, 0)
delay (1000)
Font.Draw ("Press Any Key To Continue...", 200, 30, fontd, 0)
locatexy (470, 40)
getch (ctc)


%MAIN MENU
%loop
loop
colorback (7)
cls
Font.Draw ("Choose An Option From The List:", 85, 300, fontb, 0)
y := 220
for menuptx : 1 .. 3
y := y - 50
Font.Draw (mmptxoption (menuptx), 100, y, fontd, 0)
end for
locatexy (400, 120)
get mmptxchoice
%%%%%%%%%%%%%%%%% OPTION 1 %%%%%%%%%%%%%%%%%%
if mmptxchoice = 1 then
cls
Font.Draw ("Choose Mode", 100, 300, fontb, 0)
y := 220
for playptx : 1 .. 3
y := y - 50
Font.Draw (modeptx (playptx), 100, y, fontd, 0)
end for
locatexy (400, 120)
get modechoiceptx
if modechoiceptx = 1 then
player1ptx
end if
%%%%%%%%%%%%%%%%% OPTION 2 %%%%%%%%%%%%%%%%
elsif mmptxchoice = 2 then
cls
Font.Draw ("Instructions:", 220, 300, fontb, 0)
Font.Draw ("Tap Your Key Until The X Has Reached Your Side Of The Screen", 50, 180, fontd, 0)
Font.Draw ("Player 1 Controls:", 40, 120, fontc, 0)
Font.Draw ("S Key Moves The X To The Left", 20, 80, fontd, 0)
Font.Draw ("Player 2 Controls:", 360, 120, fontc, 0)
Font.Draw ("J Key Moves The X To The Right", 340, 80, fontd, 0)
Font.Draw ("Press Any Key To Continue...", 170, 10, fontd, 0)
locatexy (430, 10)
getch (ctc)
%%%%%%%%%%%%%%%%%% OPTION 3 %%%%%%%%%%%%%%%%%%%%%%%
elsif mmptxchoice = 3 then
exit
else
rtmm
end if
end loop


why doesnt't proc X end?
Sponsor
Sponsor
Sponsor
sponsor
Bacchus




PostPosted: Fri Mar 18, 2005 9:07 pm   Post subject: (No subject)

caus e its in a loop and there no exit or exit when in it, so it just keeps going lol
mike200015




PostPosted: Fri Mar 18, 2005 11:27 pm   Post subject: (No subject)

there is an exit when
Quote:
exit when move = 0 or move = maxx
Bacchus




PostPosted: Fri Mar 18, 2005 11:43 pm   Post subject: (No subject)

oops didnt see that lol kinda hidden there Razz try
code:
exit when move <= 0 or move >= maxx
cause 305 being -10 wwont give you 0 same for maxx (but u can set to a 5 if u want)
ssr




PostPosted: Sat Mar 19, 2005 1:05 pm   Post subject: (No subject)

actually that wont fully work yet
U PUT IT IN THE WRONG LOOP!!
the exit when will only exit teh if statement not teh whole loop
just move it to right before end loop
try it

code:
setscreen ("graphics:640;400")
var y : int %%%%%%%%%%%%%%%%%%% temp?

%VARIABLE DECLARATION / ARRAY DECLARATION

var fonta := Font.New ("Amerigo BT:36")
var fontb := Font.New ("Amerigo BT:24")
var fontc := Font.New ("Amerigo BT:18")
var fontd := Font.New ("Amerigo BT:14")
var fontcountdown := Font.New ("Amerigo BT:144")

var ctc : string (1)
var movex : string (1)

var mmptxchoice : int
var modechoiceptx : int
var countdown : int := 3
var move : int := 305

var mmptxoption : flexible array 1 .. 3 of string
var modeptx : flexible array 1 .. 3 of string

mmptxoption (1) := "1. Play"
mmptxoption (2) := "2. View Instructions"
mmptxoption (3) := "3. Exit"
modeptx (1) := "1. 1 Player"
modeptx (2) := "2. 2 Players"
modeptx (3) := "3. Exit"

% PROCEDURE DECLARATION / PROCESS DECLARATION

proc X
Font.Draw ("Nobody Is Winning", 220, 100, fontc, 0)
loop
Font.Draw ("X", move, 200, fontb, 0)
drawline (315, 180, 315, 240, 0)
%drawline (0, 210, 305, 210, 0)
%drawline (335, 210, 640, 210, 0)
if hasch then
getch (movex)
if movex = "S" or movex = "s" then
move -= 10
Font.Draw ("X", move + 10, 200, fontb, 7)
elsif movex = "J" or movex = "j" then
move += 10
Font.Draw ("X", move - 10, 200, fontb, 7)
end if
cls
if move < 305 then
Font.Draw ("Player 1 Is Winning", 220, 100, fontc, 0)
elsif move > 305 then
Font.Draw ("Player 2 Is Winning", 220, 100, fontc, 0)
else
Font.Draw ("Nobody Is Winning", 220, 100, fontc, 0)
end if
end if
exit when move <= 0 or move >= maxx
end loop
end X
proc player1ptx
cls
Font.Draw ("Get Ready...", 220, 300, fontb, 0)
Font.Draw ("Press Any Key To Start The Countdown", 150, 100, fontd, 0)
locatexy (310, 50)
getch (ctc)
cls
for q : 1 .. 3
Font.Draw (intstr (countdown), 250, 150, fontcountdown, 0)
%locatexy (310, 50)
%put countdown
countdown := countdown - 1
delay (1000)
cls
end for
Font.Draw ("Go!!!", 120, 120, fontcountdown, 0)
delay (1000)
cls
X
end player1ptx

proc rtmm
cls
Font.Draw ("That Was Not An Option:", 85, 300, fontb, 0)
Font.Draw ("Redirecting To main menu", 85, 200, fontb, 0)
delay (600)
Font.Draw (".", 460, 200, fontb, 0)
delay (600)
Font.Draw (".", 470, 200, fontb, 0)
delay (600)
Font.Draw (".", 480, 200, fontb, 0)
delay (600)
end rtmm

%WELCOME MENU
color (0)
colorback (black)
cls
Font.Draw ("Welcome To Pull The X", 60, 300, fonta, 0)
delay (1000)
Font.Draw ("Press Any Key To Continue...", 200, 30, fontd, 0)
locatexy (470, 40)
getch (ctc)


%MAIN MENU
%loop
loop
colorback (7)
cls
Font.Draw ("Choose An Option From The List:", 85, 300, fontb, 0)
y := 220
for menuptx : 1 .. 3
y := y - 50
Font.Draw (mmptxoption (menuptx), 100, y, fontd, 0)
end for
locatexy (400, 120)
get mmptxchoice
%%%%%%%%%%%%%%%%% OPTION 1 %%%%%%%%%%%%%%%%%%
if mmptxchoice = 1 then
cls
Font.Draw ("Choose Mode", 100, 300, fontb, 0)
y := 220
for playptx : 1 .. 3
y := y - 50
Font.Draw (modeptx (playptx), 100, y, fontd, 0)
end for
locatexy (400, 120)
get modechoiceptx
if modechoiceptx = 1 then
player1ptx
end if
%%%%%%%%%%%%%%%%% OPTION 2 %%%%%%%%%%%%%%%%
elsif mmptxchoice = 2 then
cls
Font.Draw ("Instructions:", 220, 300, fontb, 0)
Font.Draw ("Tap Your Key Until The X Has Reached Your Side Of The Screen", 50, 180, fontd, 0)
Font.Draw ("Player 1 Controls:", 40, 120, fontc, 0)
Font.Draw ("S Key Moves The X To The Left", 20, 80, fontd, 0)
Font.Draw ("Player 2 Controls:", 360, 120, fontc, 0)
Font.Draw ("J Key Moves The X To The Right", 340, 80, fontd, 0)
Font.Draw ("Press Any Key To Continue...", 170, 10, fontd, 0)
locatexy (430, 10)
getch (ctc)
%%%%%%%%%%%%%%%%%% OPTION 3 %%%%%%%%%%%%%%%%%%%%%%%
elsif mmptxchoice = 3 then
exit
else
rtmm
end if
end loop
Very Happy eh? hopefully it works
btw u want to shorten ur codes?
Bacchus




PostPosted: Sat Mar 19, 2005 3:57 pm   Post subject: (No subject)

exit really only cause loops and for loops to exit, pretty sure it wouldnt matter if the exit is in an if cause i do it all the time
Cervantes




PostPosted: Sat Mar 19, 2005 6:16 pm   Post subject: (No subject)

Bacchus wrote:
exit really only cause loops and for loops to exit, pretty sure it wouldnt matter if the exit is in an if cause i do it all the time

Bacchus is correct. The reason your code works, ssr, is because you used the >= and <=, rather than just = and =. Bacchus was right again. Smile
ssr




PostPosted: Sat Mar 19, 2005 6:23 pm   Post subject: (No subject)

ok but try it int he if statement, it wont work for me... Sad
Sponsor
Sponsor
Sponsor
sponsor
ssr




PostPosted: Sat Mar 19, 2005 6:31 pm   Post subject: (No subject)

try these 2 codes,
one will exit and the other wont
code:
var la:int
loop
get la
if la = 1 then
put 1
exit when la = 2
end if
end loop

code:
var la:int
loop
get la
if la = 1 then
put 1
end if
exit when la = 2
end loop
mike200015




PostPosted: Sat Mar 19, 2005 6:56 pm   Post subject: (No subject)

yea.. thats tru.. only in some cases it doesnt matter.. because if its in the if statement.. then the program will only exit when it gets into the if statement, and satisfies the exit when .. but if u use an exit, not an exit when it matters.. like:
code:
var la:int
loop
get la
if la = 1 then
put 1
exit
end if
end loop

^ that will exit when u press 1.. so u need to put it in the if.. but:
code:
var la:int
loop
get la
if la = 1 then
put 1
end if
exit
end loop

^that will always exit.
ssr




PostPosted: Sat Mar 19, 2005 7:24 pm   Post subject: (No subject)

lol ya exactly, thanks for the explanation mike. Very Happy
mike200015




PostPosted: Sat Mar 19, 2005 8:23 pm   Post subject: (No subject)

haha no problem ssr Very Happy Wink
Mr. T




PostPosted: Sat Mar 19, 2005 8:54 pm   Post subject: (No subject)

horlickiki should be the one thanking you, lol
ssr




PostPosted: Sat Mar 19, 2005 9:03 pm   Post subject: (No subject)

we all learnt something didnt we... Very Happy
Bacchus




PostPosted: Sun Mar 20, 2005 12:48 am   Post subject: (No subject)

Cervantes wrote:
Bacchus was right again. Smile
wOOt!, im getting better at this Razz
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 16 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: