Page 1 of 1

Procedure how do you call it?

Posted: Thu Jun 16, 2005 5:04 pm
by Shmack
how do you call a procedure mines

procedure charRace (var str, agi, vit, wiz : int)
var choice : int
put "Pick your Race."
put " "
put "1-Human (Str: 15 Agi:15 Vit:15 Wiz:15)"
put " "
put "2-Night elf (Str: 15 Agi:20 Vit:10 Wiz:15)"
put " "
put "3-Orc (Str: 20 Agi:10 Vit:20 Wiz:10)"
put " "
put "4-Undead (Str: 10 Agi:10 Vit:20 Wiz:20)"
get choice
if choice = 1 then
race := "Human"
str := 15
agi := 15
vit := 15
wiz := 15
elsif choice = 2 then
race := "Night Elf"
str := 15
agi := 20
vit := 10
wiz := 15
elsif choice = 3 then
race := "Orc"
str := 20
agi := 10
vit := 20
wiz := 10
elsif choice = 4 then
race := "Undead"
str := 10
agi := 10
vit := 20
wiz := 20
end if
end charRace

but how do i call it i tryed just

charRace

but that doesnt work

Archived topic from Iceteks, old topic ID:3411, old post ID:27455

Procedure how do you call it?

Posted: Thu Jun 16, 2005 8:25 pm
by wtd
First off, you should use a record, rather than having individual variables for each of the stats.

Code: Select all

type PlayerStats : record
   race : string
   strength, agility, vitality, wizardry : int
end record[code]

Next you should use a case statement, rather than if, in this situation.

[code]case choice of 
   label 1:
      race := "Human"
      str := 15
      agi := 15
      vit := 15
      wiz := 15
   label 2:
      race := "Night Elf"
      str := 15
      agi := 20
      vit := 10
      wiz := 15
   label 3:
      race := "Orc"
      str := 20
      agi := 10
      vit := 20
      wiz := 10
   label 4:
      race := "Undead"
      str := 10
      agi := 10
      vit := 20
      wiz := 20
end case[code]

And of course, you don't sanity check the input.  If the user selects 5, the program runs with bad information.

Oh, and there's no reason to use a procedure, rather than a function.

[code]type PlayerStats : 
   record
      race : string
      strength, agility, vitality, wizardry : int
   end record

function selectRace : player_stats
   var choice : int
   var newChar : PlayerStats

   loop
      put "Pick your Race."
      put " "
      put "1-Human (Str: 15 Agi:15 Vit:15 Wiz:15)"
      put " "
      put "2-Night elf (Str: 15 Agi:20 Vit:10 Wiz:15)"
      put " "
      put "3-Orc (Str: 20 Agi:10 Vit:20 Wiz:10)"
      put " "
      put "4-Undead (Str: 10 Agi:10 Vit:20 Wiz:20)"

      get choice

      case choice of 
         label 1:
            newChar.race := "Human"
            newChar.strength := 15
            newChar.agility := 15
            newChar.vitality := 15
            newChar.wizardry := 15
            exit
         label 2:
            newChar.race := "Night Elf"
            newChar.strength := 15
            newChar.agility := 20
            newChar.vitality := 10
            newChar.wizardry := 15
            exit
         label 3:
            newChar.race := "Orc"
            newChar.strength := 20
            newChar.agility := 10
            newChar.vitality := 20
            newChar.wizardry := 10
            exit
         label 4:
            newChar.race := "Undead"
            newChar.strength := 10
            newChar.agility := 10
            newChar.vitality := 20
            newChar.wizardry := 20
            exit
         label:
            put "That input is invalid."
      end case
   end loop

   result newChar
end selectRace[code]

Then you could do something like:

[code]var myCharacter := selectChar[code] 

[color=#888888][size=85]Archived topic from Iceteks,  old topic ID:3411, old post ID:27458[/size][/color]

Procedure how do you call it?

Posted: Thu Jun 16, 2005 8:35 pm
by Death
For your procedure, you used parameters. When you created your procedure, you wrote charRace (var str, agi, vit, wiz: int), so when you call up your procedure, you have to insert values for those variables. so instead of calling up charRace, you will need to call up charRace (str's value, agi's value, vit's value, wiz's value). When you put a list of parameter's in a procedure (Like the ones you've shown) you have to call up the procedure and give values for the parameter. So, say you wrote charRace (15, 10, 12, 39) then the instances in your procedure would get those values (So, the first value would be your str = 15, then agi = 10, then vit = 12, then wiz = 39). For those lines of code, you shouldn't neec a procedure for it, unless you plan on repeating the same procedure numerous times. If u only plan on using that list of coding ONCE, I wouldn't create a procedure, it would be easier just to leave it out. But if you wanted to keep the procedure and make things a little more organized, I would just get rid of the parameters and used global variables. If you plan on passing the values for str, vit, agi, and wiz to other procedures, global variables would be the best thing to use. so just do something like this:

var Str, Vit, Wiz, Agi : int %Global Variables
var race : string

put "What race would you like to be? ELF, HUMAN, UNDEAD: "
get race
procedure charRace (strA, vitA, wizA, agiA : int) %Parameters
if race = "HUMAN" or race = "human" then
strA := 15
vitA := 15
wizA := 5
agiA := 20
elsif race = "ELF".....
elsif race = "UNDEAD" %And so on
end if
end charRace

%Then call it up:

charRace (Str, Vit, Wiz, Agi)
% What this lines does is it will call up your procedure. You will notice that there are your GLOBAL VARIABLES Str, Vit, Wiz and Agi in there. Those variables will gain the values u specify in the procedure. Even though the parameters are written differently (strA, vitA, wizA, agiA instead of Str, Vit, Wiz, Agi), no matter what name you call your variable, it will take the place of the parameter when it in the procedure (In other words, when you call up your procedure, Str = strA, Vit = vitA, Wiz= wizA, Agi = agiA)) so whatever values and formulas you use in your procedure that have to do with the parameters (strA, vitA, agiA, wizA), your global variables will be given the resulting values.

Archived topic from Iceteks, old topic ID:3411, old post ID:27459

Procedure how do you call it?

Posted: Thu Jun 16, 2005 8:37 pm
by Death
lol, wtd beat me to it! His example using the case statement would be much easier and more organized, so use that method instead.

Archived topic from Iceteks, old topic ID:3411, old post ID:27460

Procedure how do you call it?

Posted: Thu Jun 16, 2005 9:11 pm
by wtd
if race = "HUMAN" or race = "human" then
A suggestion: this doesn't cover something like hUman. Instead, first either completely upcase or downcase the string, then check it.

Archived topic from Iceteks, old topic ID:3411, old post ID:27464

Procedure how do you call it?

Posted: Thu Jun 16, 2005 9:11 pm
by Shmack
thx for the help guys like ALOT!!! lol hope you dont mind if i post more questions :rolleyes:

Archived topic from Iceteks, old topic ID:3411, old post ID:27465

Procedure how do you call it?

Posted: Thu Jun 16, 2005 9:26 pm
by Shmack
hmm when i try to run it its saying

"player_stats" has not been declared.

Code: Select all

type PlayerStats : 
  record
     race : string
     strength, agility, vitality, wizardry : int
  end record

function selectRace : player_stats
  var choice : int
  var newChar : PlayerStats

[code]

sorry im not that turing smart and this program is meaning for me to pass or fail  :cry:  

[color=#888888][size=85]Archived topic from Iceteks,  old topic ID:3411, old post ID:27466[/size][/color]

Procedure how do you call it?

Posted: Thu Jun 16, 2005 9:41 pm
by Shmack
ok this harder then i thought lol im still trying to get

Attcking a monster (takeing away HP from player and monster)

finding and useing items

adding to status

the only things i know how to use kinda is

Procedure, a lil bit of functions umm thats about it lmao o god this will be hard XD

but... i can do IT!! :eek:

Archived topic from Iceteks, old topic ID:3411, old post ID:27467

Procedure how do you call it?

Posted: Thu Jun 16, 2005 10:14 pm
by wtd
[quote=Shmack] hmm when i try to run it its saying

"player_stats" has not been declared.

Code: Select all

type PlayerStats : 
  record
     race : string
     strength, agility, vitality, wizardry : int
  end record

function selectRace : player_stats
  var choice : int
  var newChar : PlayerStats

[code]

sorry im not that turing smart and this program is meaning for me to pass or fail  :cry: [/quote]
 My apologies.  Replace "player_stats" with "PlayerStats". 

[color=#888888][size=85]Archived topic from Iceteks,  old topic ID:3411, old post ID:27469[/size][/color]

Procedure how do you call it?

Posted: Thu Jun 16, 2005 10:31 pm
by Death
wtd wrote:
if race = "HUMAN" or race = "human" then
A suggestion: this doesn't cover something like hUman. Instead, first either completely upcase or downcase the string, then check it.
Was there a turing function for that?

Archived topic from Iceteks, old topic ID:3411, old post ID:27470

Procedure how do you call it?

Posted: Fri Jun 17, 2005 1:00 am
by wtd
Furball wrote:
wtd wrote:
if race = "HUMAN" or race = "human" then
A suggestion: this doesn't cover something like hUman. Instead, first either completely upcase or downcase the string, then check it.
Was there a turing function for that?
Something like "toupper" and "tolowerr" or something like "Str.Upper".

Archived topic from Iceteks, old topic ID:3411, old post ID:27473

Procedure how do you call it?

Posted: Fri Jun 17, 2005 10:39 am
by Shmack
ok thc i got it workin but how do i call for the chars race str,agi,vit and wiz i tryed just typing in like put race ,strength, agility, vitality, wizardry but its saying that there not declaired

Archived topic from Iceteks, old topic ID:3411, old post ID:27475

Procedure how do you call it?

Posted: Fri Jun 17, 2005 1:52 pm
by wtd
If you've doe something like:

Code: Select all

var myCharacter := selectChar[code]

Then you could output that information with something like:

[code]put myCharacter.race
put myCharacter.strength[code]

Or, you might write a procedure like:

[code]procedure putCharacter (c : PlayerStats)
   put "Race: " ..
   put c.race
   put "Strength: " ..
   put c.strength
   % yada yada yada...
end putCharacter[code]

And then output that information with:

[code]putCharacter (myCharacter)[code] 

[color=#888888][size=85]Archived topic from Iceteks,  old topic ID:3411, old post ID:27478[/size][/color]

Procedure how do you call it?

Posted: Sat Jun 18, 2005 6:42 pm
by Shmack
ok thx guys got it im starting to work on the Attcking now and geting it to take away from my HP and the monsters HP i think i can figure that out jsut im wondering if in turing i could make some thing like a box with the arrow button you press to see more options like your internet adress bar can i do that in turing?

Archived topic from Iceteks, old topic ID:3411, old post ID:27504

Procedure how do you call it?

Posted: Sat Jun 18, 2005 10:59 pm
by Shmack
ok help!! what did i do im getting and error saying newChar cannot have '.' infront if it...

Code: Select all

 type PlayerStats :
        record
            race : string
            strength, agility, vitality, wizardry : int
        end record


    setscreen ("graphics:500;300,nocursor")
    var charName : string
    function name : string
        var charName : string
        drawline (180, 160, 330, 160, 1)
        drawline (180, 120, 330, 120, 1)
        drawline (180, 160, 180, 120, 1)
        drawline (330, 120, 330, 160, 1)
        locate (10, 25)
        put "Enter your name." ..
        locate (11, 25)
        get charName
        result charName
    end name

    procedure myStats (myCharacter : PlayerStats, charName : string)
        cls
        %draw stats box
        drawline (320, 260, 320, 100, 1)
        drawline (410, 260, 410, 100, 1)
        drawline (320, 100, 410, 100, 1)
        drawline (420, 260, 320, 260, 1)
        drawline (410, 230, 320, 230, 1)
        drawline (410, 195, 320, 190, 1)
        drawline (410, 160, 320, 160, 1)
        drawline (410, 130, 320, 130, 1)
        drawline (370, 230, 370, 100, 1)
        %Display stats in box
        locate (4, 42)
        put myCharacter.race ..
        locate (6, 48)
        put myCharacter.strength ..
        locate (8, 48)
        put myCharacter.agility ..
        locate (10, 48)
        put myCharacter.vitality ..
        locate (12, 48)
        put myCharacter.wizardry ..
        locate (6, 43)
        put "Str"
        locate (6, 43)
        put "Agi"
        locate (6, 43)
        put "Vit"
        locate (6, 43)
        put "Wiz"
        %stats bar
        drawline (10, 280, 400, 280, 1)
        drawline (10, 280, 10, 500, 1)
        drawline (400, 280, 400, 300, 1)
        locate (1, 3)
        put charName, myCharacter.race, " HP:", myCharacter.vitality * 1.5, " SP:", myCharacter.wizardry * 2.2," EXP:", "100", " z", "100000" ..
    end myStats

    function selectRace : PlayerStats
        var choice : int
        var newChar : int
        loop
            cls
            %border around chars
            drawline (370, 270, 230, 270, 1)
            drawline (230, 240, 230, 270, 1)
            drawline (370, 240, 370, 270, 1)
            drawline (130, 240, 130, 100, 1)
            drawline (490, 100, 130, 100, 1)
            drawline (490, 240, 490, 100, 1)
            drawline (490, 240, 130, 240, 1)
            locate (3, 30)
            %Chars
            put "pick your race." ..
            locate (6, 20)
            put "1-Human (Str: 15 Agi: 15 Vit: 15 Wiz: 15)"
            locate (6, 20)
            put "1-Night Elf (Str: 15 Agi: 20 Vit: 10 Wiz: 15)"
            locate (6, 20)
            put "1-Orc (Str: 20 Agi: 10 Vit: 20 Wiz: 10)"
            locate (6, 20)
            put "1-Undead (Str: 10 Agi: 10 Vit: 20 Wiz: 20)"
            locate (4, 30)
            get choice
            %Choices of chars with status
            case choice of
                label 1 :
                    newChar.race := "Human"
                    newChar.strenght := 15
                    newChar.agility := 15
                    newChar.vitality := 15
                    newChar.wizardry := 15
                    exit
                label 2 :
                    newChar.race := "Night Elf"
                    newChar.strenght := 15
                    newChar.agility := 20
                    newChar.vitality := 10
                    newChar.wizardry := 15
                    exit
                label 3 :
                    newChar.race := "Orc"
                    newChar.strenght := 20
                    newChar.agility := 10
                    newChar.vitality := 20
                    newChar.wizardry := 10
                    exit
                label 4 :
                    newChar.race := "Undead"
                    newChar.strenght := 10
                    newChar.agility := 10
                    newChar.vitality := 20
                    newChar.wizardry := 20
                    exit
                label :
                    put : "Please select a number from 1-4."
            end case
        end loop
        result newChar
    end selectRace
    charName := name
    var myCharacter := selectRace
    myStats (myCharacter, charName)[code] 

[color=#888888][size=85]Archived topic from Iceteks,  old topic ID:3411, old post ID:27507[/size][/color]