
-----------------------------------
coolest35
Mon Dec 01, 2003 7:27 pm

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...  :? 

 

% -----------------------------------------------------------------------------------------------------
% 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]

-----------------------------------
Mazer
Mon Dec 01, 2003 7:32 pm


-----------------------------------
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:



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
Mon Dec 01, 2003 8:09 pm

IT DOESN'T WORK....  :(
-----------------------------------
Hi , that what so ever doesn't make sense to me :shock: .. 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 :roll:  :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!  :lol: 


 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
Mon Dec 01, 2003 8:20 pm


-----------------------------------
ok here is what u do... compile it to an exe, then use Sys.Exec at the end

-----------------------------------
coolest35
Mon Dec 01, 2003 8:26 pm

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
Mon Dec 01, 2003 8:33 pm


-----------------------------------
have
 if reply="y" and Sys.Exec "battleship.exe" then
end if


-----------------------------------
AsianSensation
Mon Dec 01, 2003 8:38 pm


-----------------------------------
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:

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
Mon Dec 01, 2003 8:40 pm


-----------------------------------
if ur gonna do that, dont define any variables in the loop or it'll crash

-----------------------------------
Mazer
Mon Dec 01, 2003 8:49 pm


-----------------------------------
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
Mon Dec 01, 2003 8:52 pm


-----------------------------------
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
Mon Dec 01, 2003 8:56 pm


-----------------------------------
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
Mon Dec 01, 2003 8:58 pm


-----------------------------------
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
Mon Dec 01, 2003 8:58 pm

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:  :?:

-----------------------------------
Mazer
Mon Dec 01, 2003 9:06 pm


-----------------------------------
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
Mon Dec 01, 2003 9:10 pm

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

-----------------------------------
Mazer
Mon Dec 01, 2003 9:20 pm


-----------------------------------
aww... but i don't get any bits on msn... hehe. yeah, ncoutsos@hotmail.com

-----------------------------------
Andy
Mon Dec 01, 2003 9:23 pm


-----------------------------------
here u go nick
var runtime, count, starttime := 0
put "run for how many seconds?"
get runtime
runtime *= 1000

%Declaring variables
var colback, ballcol : int
var x := maxx div 2
var y := maxy div 2

%Procedure
proc circle
    randint (ballcol, 5, 225)
    drawfilloval (x, y, 20, 20, ballcol)
end circle

%Setting screen
setscreen ("nocursor")

%loop statement
loop

    loop

        randint (colback, 5, 50)
        drawfillbox (0, 0, maxx, maxy, colback)
        drawdot (1, -10, (Time.Elapsed mod 255) + 1)
        count := Time.Elapsed div 255
        if (255 * (count + 1)) > runtime then
            if (255 * count) + whatdotcolor (1, -10) - 1 > runtime then
                return
            end if
        end if
        %Exiting from the program
        exit when x < 10 or x > maxx - 10 or y < 10 or y > maxy - 10
        circle
        delay (50)
        drawfilloval (x, y, 20, 20, colback)
        randint (x, x - 15, x + 15)
        randint (y, y - 15, y + 15)
    end loop
    x := maxx div 2
    y := maxy div 2

end loop



-----------------------------------
Mazer
Mon Dec 01, 2003 9:35 pm


-----------------------------------
my goodness. you truly are the Whatdotcolor Warrior. i'm gonna start a petition to get your name/rank changed accordingly. honestly

-----------------------------------
Andy
Mon Dec 01, 2003 9:40 pm


-----------------------------------
oops, thats for DBZ's program... damn oh well...

-----------------------------------
Mazer
Mon Dec 01, 2003 9:42 pm


-----------------------------------
doesn't matter. you're still the WW
