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

Username:   Password: 
 RegisterRegister   
 Loop inside a function
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
coolest35




PostPosted: Mon Dec 01, 2003 7:27 pm   Post subject: Loop inside a function

Hi Smile , 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" Sad .. what is the problem Question 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... Confused

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

% Set the font type, size and colour

        font1 := Font.New ("Trebuchet MS:75")
        assert font1 > 0
       
        % 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



[center][/center]
Sponsor
Sponsor
Sponsor
sponsor
Mazer




PostPosted: Mon Dec 01, 2003 7:32 pm   Post subject: (No subject)

yeah, you can't have a file include itself in the file... otherwise you'd have one infinitely big file and just about zero hard drive space.

make the you win program into a proc:

code:


proc winscreen
% 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

% Set the font type, size and colour

        font1 := Font.New ("Trebuchet MS:75")
        assert font1 > 0
       
        % 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




PostPosted: Mon Dec 01, 2003 8:09 pm   Post subject: IT DOESN'T WORK.... :(

Hi , that what so ever doesn't make sense to me Shocked .. and i did my best to try that out.. but it seems to create about 20 other Confused errors in the rest of my game... so thankz Rolling Eyes Wink 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! Laughing


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




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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
Sponsor
sponsor
Mazer




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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: :?:


YouLoose.t
 Description:

Download
 Filename:  YouLoose.t
 Filesize:  1.45 KB
 Downloaded:  102 Time(s)


Victory.t
 Description:

Download
 Filename:  Victory.t
 Filesize:  1.5 KB
 Downloaded:  116 Time(s)


bswork111.t
 Description:

Download
 Filename:  bswork111.t
 Filesize:  10.3 KB
 Downloaded:  138 Time(s)


bsinfo.t
 Description:

Download
 Filename:  bsinfo.t
 Filesize:  3.47 KB
 Downloaded:  113 Time(s)


battleship12.t
 Description:

Download
 Filename:  battleship12.t
 Filesize:  4.27 KB
 Downloaded:  114 Time(s)


battleship12.t
 Description:

Download
 Filename:  battleship12.t
 Filesize:  4.27 KB
 Downloaded:  112 Time(s)

Mazer




PostPosted: 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




PostPosted: 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
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  [ 20 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: