Posted: Mon Dec 01, 2003 7:27 pm Post subject: Loop inside a function
Hi , i made a game battleship, i used subprograms in it.. like the winning screen for example... but after the winning scren has shown i want to ask the user if they want to play again, when i put " include 'battleshipmainfile.t' it says " RECURSIVE USE OF "BATTLESHIPMAIN.T" .. what is the problem and how do i fix it... so it loops over and over..
below is the code that i have for the winning screen right now...
code:
% -----------------------------------------------------------------------------------------------------
% You Win Program
% Written By: ...
% Date Written: 11/21/03
%
% Input : None
% Output : An animation in different colours, stating that the user has won the game.
% Process : Randomly generates random colours in sequences, and displays them in the specified text given.
% ------------------------------------------------------------------------------------------------------
% Declare All Variables
var font1: int
var colo,colo1 :int
% Set the screen size
setscreen ("graphics: 800;600")
% Loop the program so the font colour is endlessly generated
% until the user terminates the program
loop
% Randomly generates differend font colours
randint (colo,1,100)
randint (colo1,1,100)
% Delay is set so that the colours don't distort
delay (100)
% Set the background, and font colour
colorback (black)
color (colo)
% Cls is put in so the animation is played without flickering
cls
% Display the output in the font type, size, and colour that was specified
Font.Draw ("Victory Is Yours!", 50, 330, font1, colo)
% Set a delay so the animation is played without flickering
delay (50)
% Release the memory that was used by the randomly generated colours
Font.Free (font1)
% End the loop so the program continues over and over
end loop
end winscreen
now, put your main game in a loop and at the line where it has the inlcude line to show the winning screen, replace it with winscreen and at the part where it asks the user if s/he wants to play again, just have an if statement that will exit the loop if the answer is no.
coolest35
Posted: Mon Dec 01, 2003 8:09 pm Post subject: IT DOESN'T WORK.... :(
Hi , that what so ever doesn't make sense to me .. and i did my best to try that out.. but it seems to create about 20 other errors in the rest of my game... so thankz to the guy who posted it.. anyway.. but if anyone else has a easier and a clearear ( don't think that's spelt correctly but meh ) please post it!
Quote:
now, put your main game in a loop and at the line where it has the inlcude line to show the winning screen, replace it with winscreen and at the part where it asks the user if s/he wants to play again, just have an if statement that will exit the loop if the answer is no.
Andy
Posted: Mon Dec 01, 2003 8:20 pm Post subject: (No subject)
ok here is what u do... compile it to an exe, then use Sys.Exec at the end
coolest35
Posted: Mon Dec 01, 2003 8:26 pm Post subject: Sys.Exec
Ok i did this :
if reply = "y" then
sys.exec " Battleship.exe"
what do i do .. it comes up as an error .. if some can fix that code up plz do so.. thnx...i'm having trouble with it!
Andy
Posted: Mon Dec 01, 2003 8:33 pm Post subject: (No subject)
have
code:
if reply="y" and Sys.Exec "battleship.exe" then
end if
AsianSensation
Posted: Mon Dec 01, 2003 8:38 pm Post subject: (No subject)
don't listen to dodge, Sys.Exec is what I used on my program when I got lazy.
you don't even have to use include.
when you want to exit the winning screen do something like this:
code:
Font.Draw ("Press any key to continue", 50, 130, font1, colo)
if hasch then
exit
end if
put that into the main loop, now whenever they press a key when that shows up, then it takes them back to the main loop again, so they can play it again.
Andy
Posted: Mon Dec 01, 2003 8:40 pm Post subject: (No subject)
if ur gonna do that, dont define any variables in the loop or it'll crash
Sponsor Sponsor
Mazer
Posted: Mon Dec 01, 2003 8:49 pm Post subject: (No subject)
coolest, that shouldn't have given you errors. could you post the code so i can see what you did? otherwise dodge is going to suggest how to make the game loop using whatdotcolour
AsianSensation
Posted: Mon Dec 01, 2003 8:52 pm Post subject: (No subject)
maybe he had couple of variables all with the same name? When you do that and then use include, it will give you an error. There were tons of errors with mine when I tried to use include in my final project. And since I found that out at the last moment, I got lazy and didn't fix it by renaming everything. So I made bunch of stuff into executables, and then use Sys.Exec to access them, lol.
Andy
Posted: Mon Dec 01, 2003 8:56 pm Post subject: (No subject)
if u wana use whatdotcolor for that... keep on drawing dots outside of the screen and then you can measure the number of dots.. lol if you wanna know how, post here
Mazer
Posted: Mon Dec 01, 2003 8:58 pm Post subject: (No subject)
i told you so. well, let's have it dodge, show us the way of the Whatdotcolor Warrior (hey... that could be a movie...)
warning: coolest35, if you actually care to understand how to solve your problem, ignore dodge's whatdotcolor post (no offence to dodge)
coolest35
Posted: Mon Dec 01, 2003 8:58 pm Post subject: ok...
ok .. i listen to both of you and did the stuff u told me it worked.. but after the hash part.. i put include "battleship12.t" ( main file name instead of the .exe ) it doesn't work.. ok.. i have submitted as attachments the main files.. just comment out the picture parts so it works.. ok.. and thanx to all who help.. i'm sooooooo confused... :cry: :?:
Posted: Mon Dec 01, 2003 9:06 pm Post subject: (No subject)
hmm.... couldn't run it even after commenting out the picture parts because there are other included files that you left out, and after commenting those out i got errors of some window variable not being declared.
where should i be looking for the end of the game when the victory/defeat screen is displayed and the user is asked if they want to play again?
coolest35
Posted: Mon Dec 01, 2003 9:10 pm Post subject: BSRESULT
it should be in the bsresult .. which says to include the file VICTORY.T which is attached... uh MAZOR do u have msn or any chatting program.. because i am getting tired of posting messages i'll ask u directly