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

Username:   Password: 
 RegisterRegister   
 Trying to call varuables from another source.
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
TWizard




PostPosted: Wed Jun 30, 2010 3:25 am   Post subject: Trying to call varuables from another source.

What is it you are trying to achieve?
Im trying to finish up on a game i started and wanted to know
if there was a way to call varuables from a procedure or
a file so i could make it more flexible or update varuables that
where already called above

What is the problem you are having?
My problem is calling varuables above from a file or a procedure
"I already know if a varuable is called in a procedure it can not
be called out side the procedure".

Describe what you have tried to solve this problem
iIwas trying to learn more on how to load files from other places
that and I was trying to look around useing a function,process,
class.

Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Look aside the picture and music. Thats as small as i could get it.

Turing:


<setscreen ("graphics:700;600,nobuttonbar,position:truemiddle,centre")

process Menu_Music
    Music.PlayFileLoop ("Menu_Screen_Music.mp3")
end Menu_Music

process Ingame_Music
    Music.PlayFileLoop ("Ingame Music.mp3")
end Ingame_Music

process Attack_Sound
    Music.PlayFile ("Attack.wav")
end Attack_Sound

process Click
    Music.PlayFile ("Click.wav")
end Click

process Sound_Lost
    Music.PlayFile ("Sound Lost.wav")
end Sound_Lost

process Sound_Won
    Music.PlayFile ("Sound Won.wav")
end Sound_Won

process Sound_Defended
    Music.PlayFile ("Defend.wav")
end Sound_Defended

process Game_Lost
    Music.PlayFile ("Lost.mp3")
end Game_Lost

process Game_Won
    Music.PlayFile ("Won.mp3")
end Game_Won

var civilization_number, total_number : int
civilization_number := Rand.Int (2, 25)
total_number := civilization_number
var mousex, mousey, button : int
var number, number1, number2 : int
var x_location, y_location : array 1 .. civilization_number of int
var civilization_name : array 1 .. civilization_number of string (20)
var female, male : array 1 .. civilization_number of int
var player_soldiers : array 1 .. civilization_number of int
var death : array 1 .. civilization_number of boolean
var random, ending_game : int
var clr : int := 218
var text1 : int := Font.New ("Times New Roman:50:Bold")
var text2 : int := Font.New ("Times New Roman:30:Bold")
var User_Name, created_by, game_over, game_winner : string (20)
var castle : int := Pic.FileNew ("Castle.bmp")
var castle_player : int := Pic.FileNew ("Castle_Player.bmp")
var images1, images2 : array 1 .. 32 of int
var fire_number : int := 1
var images_1, images_2, images_3, images_4 : array 1 .. 16 of int
var gate_number : int
var gate_picture : array 1 .. 17 of int

User_Name := "User_Name"
created_by := "Created By:"
game_over := "!Defeat!"
game_winner := "!Victory!"

for i : 1 .. 16
    images_1 (i) := Pic.FileNew ("gate_bar (" + intstr (i) + ")" + ".bmp")
    images_2 (i) := Pic.FileNew ("gate_bar1 (" + intstr (i) + ")" + ".bmp")
    images_3 (i) := Pic.FileNew ("gate_bar2 (" + intstr (i) + ")" + ".bmp")
    images_4 (i) := Pic.FileNew ("gate_bar3 (" + intstr (i) + ")" + ".bmp")
end for

for i : 1 .. 17
    gate_picture (i) := Pic.FileNew ("gate " + intstr (i) + ".bmp")
end for

for i : 1 .. 32
    images1 (i) := Pic.FileNew ("Fire1 (" + intstr (i) + ")" + ".bmp")
    images2 (i) := Pic.FileNew ("Fire2 (" + intstr (i) + ")" + ".bmp")
end for

proc Loading_var
    for i : 1 .. civilization_number
        female (i) := 1
        male (i) := 1
        death (i) := false
        civilization_name (i) := "Civilization: " + intstr (i)
        player_soldiers (i) := 0
    end for
    ending_game := 0
end Loading_var

proc Civilization_Loading
    for i : 1 .. civilization_number
        x_location (i) := Rand.Int (10, 660)
        y_location (i) := Rand.Int (10, 460)
    end for
end Civilization_Loading

proc Civilization_Maped
    for i : 2 .. civilization_number
        if death (i) = false then
            Pic.Draw (castle, x_location (i), y_location (i), 0)
        end if
    end for
    Draw.Line (0, 500, 700, 500, red)
    Pic.Draw (castle_player, x_location (1), y_location (1), 0)
end Civilization_Maped

proc Civilization_Menu
    gate_number := 1
    for i : 1 .. 17
        Pic.Draw (gate_picture (gate_number), 0, 0, 0)
        gate_number := gate_number + 1
        if gate_number = 18 then
            gate_number := 1
        end if
        delay (50)
    end for
end Civilization_Menu

proc opening
    gate_number := 1
    for i : 1 .. 16
        Pic.Draw (images_1 (gate_number), 248, 196, 0)
        Pic.Draw (images_2 (gate_number), 248, 150, 0)
        Pic.Draw (images_3 (gate_number), 248, 102, 0)
        Pic.Draw (images_4 (gate_number), 248, 47, 0)
        gate_number := gate_number + 1
        if gate_number = 17 then
            gate_number := 1
        end if
        delay (50)
    end for
end opening

proc closing
    gate_number := 16
    for i : 1 .. 16
        Pic.Draw (images_1 (gate_number), 248, 196, 0)
        Pic.Draw (images_2 (gate_number), 248, 150, 0)
        Pic.Draw (images_3 (gate_number), 248, 102, 0)
        Pic.Draw (images_4 (gate_number), 248, 47, 0)
        gate_number := gate_number - 1
        if gate_number = -1 then
            gate_number := 16
        end if
        delay (50)
    end for
end closing

procedure decreas
    for decreasing i : 31 .. 16
        colourback (i)
        delay (25)
        cls
    end for
end decreas

procedure increas
    for i : 16 .. 31
        colourback (i)
        delay (25)
        cls
    end for
end increas

procedure Game_Over
    Music.PlayFileStop
    fork Game_Lost
    decreas
    for i : 0 .. 39
        RGB.SetColor (clr, 0, i / 39, 0)
        Font.Draw (game_over, (350) - (Font.Width (game_over, text1) div 2), (300) - 9, text1, clr)
        delay (50)
    end for
    delay (2750)
end Game_Over

procedure Game_Winner
    Music.PlayFileStop
    fork Game_Won
    decreas
    for i : 0 .. 39
        RGB.SetColor (clr, 0, i / 39, 0)
        Font.Draw (game_winner, (350) - (Font.Width (game_winner, text1) div 2), (300) - 9, text1, clr)
        delay (50)
    end for
    delay (2750)
end Game_Winner

procedure intro
    for i : 0 .. 39
        RGB.SetColor (clr, i / 39, 0, i / 39)
        Font.Draw (created_by, (350) - (Font.Width (created_by, text1) div 2), (300) - 9, text1, clr)
        delay (30)
    end for
    delay (250)
    for i : 0 .. 39
        RGB.SetColor (clr, 0, i / 39, i / 39)
        Font.Draw (sawyer_chamaillard, (350) - (Font.Width (sawyer_chamaillard, text2) div 2.5), (250) - 9, text2, clr)
        delay (30)
    end for
    for decreasing i : 39 .. 0
        RGB.SetColor (clr, i / 39, 0, i / 39)
        Font.Draw (created_by, (350) - (Font.Width (created_by, text1) div 2), (300) - 9, text1, clr)
        delay (30)
    end for
    delay (250)
    for decreasing i : 39 .. 0
        RGB.SetColor (clr, 0, i / 39, i / 39)
        Font.Draw (sawyer_chamaillard, (350) - (Font.Width (sawyer_chamaillard, text2) div 2.5), (250) - 9, text2, clr)
        delay (30)
    end for
end intro

proc Team_var
    if player_soldiers (number1) >= player_soldiers (number2) then
        player_soldiers (number1) := player_soldiers (number1) - player_soldiers (number2)
        player_soldiers (number2) := 0
        fork Sound_Defended
        delay (250)
    end if
    if player_soldiers (number2) >= player_soldiers (number1) then
        player_soldiers (number2) := player_soldiers (number2) - player_soldiers (number1)
        player_soldiers (number1) := 0
        fork Sound_Lost
        delay (250)
    end if
    if player_soldiers (number1) >= 0 then
        male (number2) := male (number2) - player_soldiers (number1) div 2
        female (number2) := female (number2) - player_soldiers (number1) div 2
    end if
    if male (number2) <= 0 or female (number2) <= 0 then
        fork Sound_Won
        delay (2500)
        death (number2) := true
        total_number := total_number - 1
    end if
    if male (1) <= 0 or female (1) <= 0 then
        death (1) := true
    end if
end Team_var

proc population_groth
    random := Rand.Int (1, 2)
    if random = 1 then
        male (number) := male (number) + female (number)
    elsif random = 2 then
        female (number) := female (number) + female (number)
    end if
end population_groth

proc computer
    random := Rand.Int (1, 3)
    if random = 1 and death (1) = true then
        random := Rand.Int (1, civilization_number)
        var pos : int := 1
        for i : 1 .. civilization_number
            if player_soldiers (i) >= 1 then
                for j : pos .. civilization_number
                    pos += 1
                    if random = i then
                        number1 := number
                        number2 := i
                        if number = i then
                            number2 := j
                        end if
                        Team_var
                    end if
                end for
            end if
        end for
        random := Rand.Int (1, 2)
        if random = 1 then
            random := Rand.Int (0, male (number) - 1)
            male (number) := male (number) - random
            player_soldiers (number) := player_soldiers (number) + random
        elsif random = 2 then
            random := Rand.Int (0, player_soldiers (number))
            male (number) := male (number) + random
            player_soldiers (number) := player_soldiers (number) - random
        end if
    elsif random = 2 then
    elsif random = 3 then
    end if
end computer

proc population
    number := 1
    population_groth
    for i : 2 .. civilization_number
        if death (i) = false then
            number := i
            computer
            population_groth
        end if
    end for
end population

proc Player_Lost_Won
    if death (1) = true then
        ending_game := 2
    end if
    if total_number = 0 then
        ending_game := 1
    end if
end Player_Lost_Won

proc Civilization_Borders
    var pos : int
    var collision : boolean
    loop
        pos := 2
        collision := false
        Civilization_Loading
        for i : 1 .. civilization_number
            for j : pos .. civilization_number
                if x_location (i) >= x_location (j) - 20 and x_location (i) <= x_location (j) + 20 and y_location (i) >= y_location (j) - 20 and y_location (i) <= y_location (j) + 20 then
                    collision := true
                    exit
                end if
            end for
            if collision = true then
                exit
            end if
            pos += 1
        end for
        exit when collision = false
    end loop
end Civilization_Borders

proc Civilization_Finding
    if death (1) = false and button = 1 and mousex >= x_location (1) and mousex <= x_location (1) + 20 and mousey >= y_location (1) and mousey <= y_location (1) + 24 then
        fork Click
        loop
            Mouse.Where (mousex, mousey, button)
            Civilization_Maped
            put "[View Status]"
            put "[Train Unite]"
            put "[Exit]"
            if button = 1 and mousex >= 3 and mousex <= 100 and mousey >= 585 and mousey <= 595 then
                fork Click
            end if
            if button = 1 and male (1) >= 20 and mousex >= 3 and mousex <= 100 and mousey >= 570 and mousey <= 580 then
                fork Click
                player_soldiers (1) := player_soldiers (1) + 10
                male (1) := male (1) - 10
            end if
            if button = 1 and mousex >= 3 and mousex <= 44 and mousey >= 553 and mousey <= 563 then
                fork Click
                exit
            end if
            put civilization_name (1)
            put "Male:", male (1), " Female:", female (1)
            put "Soldiers:", player_soldiers (1)
            delay (25)
            cls
        end loop
    end if
    for i : 2 .. civilization_number
        if death (i) = false and button = 1 and mousex >= x_location (i) and mousex <= x_location (i) + 20 and mousey >= y_location (i) and mousey <= y_location (i) + 24 then
            fork Click
            loop
                Mouse.Where (mousex, mousey, button)
                Civilization_Maped
                put "[Spy]"
                put "[Attack]"
                put "[Exit]"
                put civilization_name (i)
                if button = 1 and mousex >= 3 and mousex <= 37 and mousey >= 585 and mousey <= 595 then
                    put "Male:", male (i), " Female:", female (i)
                    put "Soldiers:", player_soldiers (i)
                end if
                if button = 1 and mousex >= 3 and mousex <= 60 and mousey >= 570 and mousey <= 580 then
                    fork Attack_Sound
                    delay (2000)
                    number1 := 1
                    number2 := i
                    Team_var
                end if
                if button = 1 and mousex >= 3 and mousex <= 44 and mousey >= 553 and mousey <= 563 or death (i) = true or death (1) = true then
                    fork Click
                    exit
                end if
                delay (25)
                cls
            end loop
        end if
    end for
end Civilization_Finding

proc Game
    loop
        Mouse.Where (mousex, mousey, button)
        put "[End Turn]"
        put "[Menu]"
        if button = 1 and mousex >= 3 and mousex <= 73 and mousey >= 585 and mousey <= 595 or death (1) = true then
            fork Click
            population
        end if
        Player_Lost_Won
        if button = 1 and mousex >= 3 and mousex <= 76 and mousey >= 570 and mousey <= 580 or death (1) = true or ending_game = 1 then
            if ending_game = 1 then
                Game_Winner
                fork Menu_Music
                exit
            end if
            if ending_game = 2 then
                Game_Over
                Music.PlayFileStop
                fork Menu_Music
                exit
            end if
            fork Click
            Music.PlayFileStop
            fork Menu_Music
            cls
            decreas
            exit
        end if
        Civilization_Finding
        Civilization_Maped
        delay (25)
        cls
    end loop
end Game

proc Game_Menu
    Civilization_Menu
    opening
    loop
        Mouse.Where (mousex, mousey, button)
        if button = 1 and mousey >= 212 and mousey <= 234 and mousex >= 299 and mousex <= 399 then
            fork Click
            closing
            Music.PlayFileStop
            fork Ingame_Music
            Loading_var
            Civilization_Borders
            increas
            Game
            Civilization_Menu
            opening
        end if
        if button = 1 and mousey >= 163 and mousey <= 186 and mousex >= 299 and mousex <= 399 then
            fork Click
        end if
        if button = 1 and mousey >= 115 and mousey <= 140 and mousex >= 299 and mousex <= 399 then
            fork Click
            closing
            decreas
            colourback (black)
            intro
            Civilization_Menu
            opening
        end if
        if button = 1 and mousey >= 70 and mousey <= 93 and mousex >= 299 and mousex <= 399 then
            fork Click
            closing
            Music.PlayFileStop
            exit
        end if
        fire_number := fire_number + 1
        if fire_number = 33 then
            fire_number := 1
        end if
        Pic.Draw (images1 (fire_number), 1, 1, 0)
        Pic.Draw (images2 (fire_number), 571, 1, 0)
        delay (50)
    end loop
end Game_Menu

fork Menu_Music
Game_Menu



Please specify what version of Turing you are using
Turing 4.0.5
Any help would be most helpful.
"Even if its negative so i can start another".
Sponsor
Sponsor
Sponsor
sponsor
Cezna




PostPosted: Wed Jun 30, 2010 8:52 am   Post subject: Re: Trying to call varuables from another source.

First, it is variables, not varuables.
Second, in the future, post an attachment instead of copy-pasting the code, as that is too much code to read through.

Third, try using:
Turing:

include ("'file name here'.t")


You probably shouldn't be using variables in a seperate file though, if I correctly understand your problem, which I am not totally sure I do.

DemonWasp




PostPosted: Wed Jun 30, 2010 9:12 am   Post subject: RE:Trying to call varuables from another source.

It sounds to me like what you want are "parameters". The syntax goes like this:

Turing:

proc doThings ( parameter : int )
    % Fill this in for yourself
end doThings


You can then call it as follows:
Turing:

var a : int := 3
doThings ( a )
% or...
doThings ( 3 )


You can also use parameters with functions, but not with processes.

You need to master parameters before you move onto learning about classes. Object-oriented programming is difficult enough at first without missing knowledge on basic things like parameters.
TWizard




PostPosted: Wed Jun 30, 2010 12:19 pm   Post subject: RE:Trying to call varuables from another source.

Well mainly what I was trying to do was reset all the civilization_numbers so they can have a new number. When I run it now and click play and say there where 5 castles including my self
then click exit and play again there are still 5 castles. I wanted to know if I could run the program from the top again with out haveing to close and reopen it or open from another source because when I use a procedure I cant call the varuables outside of it. I was hopeing to learn more about useing the file's. I'v been creating games since my com tech class which the teacher was no help and I wanted to learn more so I would be able to goback and rebuild some of my other games. Thanks for the posting.
Cezna




PostPosted: Wed Jun 30, 2010 9:14 pm   Post subject: RE:Trying to call varuables from another source.

Just put the initilizations and the loop you have now in one big loop, and go to the beginning of this loop when you want to restart the game.
TWizard




PostPosted: Thu Jul 01, 2010 1:03 pm   Post subject: RE:Trying to call varuables from another source.

Lol. Thank you did'nt think of that before i also have another idea im going to try. Thanks for the posts.
Cezna




PostPosted: Sat Jul 03, 2010 9:15 am   Post subject: RE:Trying to call varuables from another source.

No prob.
Btw, very cool avatar (much betta than mine)!
TWizard




PostPosted: Thu Jul 28, 2011 4:12 pm   Post subject: RE:Trying to call varuables from another source.

Mmm I seems turing allows this to run only so many times, though i moved on, but i just wanted finish up this post.
Sponsor
Sponsor
Sponsor
sponsor
Zren




PostPosted: Thu Jul 28, 2011 11:19 pm   Post subject: RE:Trying to call varuables from another source.

Did you free the images before reloading them? Or just don't reload them? Turing only has memory space for 1000 images.
TWizard




PostPosted: Thu Aug 11, 2011 11:30 pm   Post subject: RE:Trying to call varuables from another source.

Well, i'v lost interest with this game, i have started a new game in which i'm hoping to get some help on.
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 1  [ 10 Posts ]
Jump to:   


Style:  
Search: