Computer Science Canada

Glitch help in my program!

Author:  xBalmungx [ Tue Jan 12, 2010 6:47 pm ]
Post subject:  Glitch help in my program!

What is it you are trying to achieve?
To make a program that resembles a text based game


What is the problem you are having?
That the text disappears before anyone can read it, the sound file also does not work, and only works at the first 3 seconds, then stops, or when you click the red X to close the window....


Describe what you have tried to solve this problem
Moving around the music, nothing yet for the text


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
import GUI
setscreen ("graphics:max,max,nobuttonbar,msdos")
colorback (255)
cls
color (12)

process BackgroundMusic
loop
Music.PlayFileLoop ("Guns N' Roses - Shackler's Revenge.mp3")
end loop
end BackgroundMusic

fork BackgroundMusic
var command : string
var key : string (1)
const PIC_ID := Pic.FileNew ("mentalroom.jpg")
const PIC_ID2 := Pic.FileNew ("headset.jpg")
const PIC_ID3 := Pic.FileNew ("bloodstains.jpg")
const PIC_ID4 := Pic.FileNew ("paper_ball.jpg")
const PIC_ID5 := Pic.FileNew ("knife.jpg")
const PIC_ID6 := Pic.FileNew ("Zombie.jpg")
var keyboardinput:int
var Health : int
var username : string
var knife_answer : string
var menu_choice : int
var chars :array char of boolean
var death :int


% put "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ESCAPE@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
% put "__________________________________MENU________________________________"
% put skip
% procedure Test
% locate (1,1)
% put "Welcome!"
% end Test
%
% procedure Test2
% locate (1,1)
% put "This might be the instructions"
% end Test2
%
% var button1:int:=GUI.CreateButton(200,200,12,"Start Game",Test)
% var button2:int:=GUI.CreateButton(200,400,12,"Instructions?",Test2)
% loop
% exit when GUI.ProcessEvent
% end loop



put "PLEASE ENTER YOUR USERNAME"
get username
cls
if username = "Pablo" then
loop
color (1)
put "PABLO IS A TREEE!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!"
color (2)
put "PABLO IS A TREEE!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!"
color (3)
put "PABLO IS A TREEE!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!"
color (4)
put "PABLO IS A TREEE!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!"
color (5)
put "PABLO IS A TREEE!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!"
color (6)
put "PABLO IS A TREEE!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!"
color (7)
put "PABLO IS A TREEE!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!"
color (8)
put "PABLO IS A TREEE!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!"
color (9)
put "PABLO IS A TREEE!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!"
color (10)
put "PABLO IS A TREEE!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!"
color (11)
put "PABLO IS A TREEE!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!"
color (12)
put "PABLO IS A TREEE!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!"
color (13)
put "PABLO IS A TREEE!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!"
color (14)
put "PABLO IS A TREEE!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!"
color (15)
put "PABLO IS A TREEE! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!"
color (1)
put "PABLO IS A TREEE!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!"
color (2)
put "PABLO IS A TREEE!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!"
color (3)
put "PABLO IS A TREEE!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!"
color (4)
put "PABLO IS A TREEE!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!"
color (5)
put "PABLO IS A TREEE!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!"
color (6)
put "PABLO IS A TREEE!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!"
color (7)
put "PABLO IS A TREEE!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!"
color (8)
put "PABLO IS A TREEE!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!"
color (9)
put "PABLO IS A TREEE!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!"
color (10)
put "PABLO IS A TREEE!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!"
color (11)
put "PABLO IS A TREEE!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!"
color (12)
put "PABLO IS A TREEE!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!"
color (13)
put "PABLO IS A TREEE!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!"
color (14)
put "PABLO IS A TREEE!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!"
end loop
end if

put ""
put "Please wait while the game loads"
put " "
put " "
locate (35, 126)
put "PRESS ANY KEY TO CONTINUE"
locate (35, 126)
getch (key)
cls
put "Loading Screen."
delay (250)
cls
put "Loading Screen.."
delay (250)
cls
put "Loading Screen..."
delay (250)
cls
put "Loading Screen...."
delay (250)
cls
put "Loading Screen....."
delay (250)
cls
put "Loading Screen...."
delay (250)
cls
put "Loading Screen..."
delay (250)
cls
put "Loading Screen.."
delay (250)
cls
put "Loading Screen."
delay (250)
cls
put "Loading Screen.."
delay (250)
cls
put "Loading Screen..."
delay (250)
cls
put "Loading Screen...."
delay (250)
cls
put "Loading Screen....."
delay (250)
cls
put "Loading Screen...."
delay (250)
cls
put "Loading Screen..."
delay (250)
cls
put "Loading Screen.."
delay (250)
cls
put "Loading Screen."
delay (250)
cls
locate (25, 65)
put "*Where am I?*"
put " "
put " "
locate (35, 126)
put "PRESS ANY KEY TO CONTINUE"
locate (35, 126)
getch (key)
cls
locate (25, 65)
put "*I can't see anything?*"
put " "
put " "
locate (35, 126)
put "PRESS ANY KEY TO CONTINUE"
locate (35, 126)
getch (key)
cls
locate (25, 65)
put "Welcome?" ..
locate (25, 65)
put "My name is Friend."
put " "
put " "
locate (35, 126)
put "PRESS ANY KEY TO CONTINUE"
locate (35, 126)
getch (key)
cls
locate (25, 65)
put "*What am I doing here?Friend?*"
put " "
put " "
locate (35, 126)
put "PRESS ANY KEY TO CONTINUE"
locate (35, 126)
getch (key)
cls
locate (25, 65)
put "How about you reach upwards, there should be a string"
locate (26, 65)
put "**You reach and find the string**"
locate (27, 65)
put "Pull it?now"
put " "
put " "
locate (35, 126)
put "PRESS ANY KEY TO CONTINUE"
locate (35, 126)
getch (key)
cls
locate (22, 65)
put "The following commands for this situation are..."
locate (23, 65)
put "Pull the string?PULL"
locate (24, 65)
put "Don't trust this *friend* guy, you can manage on your own?LEAVE"
locate (25, 65)
get command
case command of
label "PULL" :
cls
colorback (0)
cls
put "**A light flickers on, and you realize that the string was attached to the light**"
put "Well that wasn't so hard now was it?"
put "Why don't you have a look around where you are right now..."
put " "
put " "
locate (35, 126)
put "PRESS ANY KEY TO CONTINUE"
locate (35, 126)
getch (key)
cls
Pic.Draw (PIC_ID, 0, 0, picCopy)
put " "
put " "
locate (35, 126)
put "PRESS ANY KEY TO CONTINUE"
locate (35, 126)
getch (key)
cls
put ""
put "You see, right now, in this situation, I'm the best hope you have of surviving."
put "Look on the table, there should be a headset there...pick it up..."
put "**You go to pick it up, and find a note underneath**"
Pic.Draw (PIC_ID3, 0, 0, picCopy)
put " "
put " "
locate (35, 126)
put "PRESS ANY KEY TO CONTINUE"
locate (35, 126)
getch (key)
cls
put "The commands for this situation are..."
put "Read the note...Read"
put "Leave the note alone...Leave"
get command
cls
if command = "Read" then
put ""
put "**It reads...'IF SOMEONE FINDS THIS NOTE, DO NOT TRUST THE PERSON NAMED 'FRIEND'..."
put "**It looks like the note goes on, but the rest is covered by blood**"
put " "
put " "
locate (35, 126)
put "PRESS ANY KEY TO CONTINUE"
locate (35, 126)
getch (key)
cls
elsif command = "Leave" then
put ""
put "**You crumple the paper and throw it into a corner, your hand is briefly stained with fresh blood from the note**"
Pic.Draw (PIC_ID4, 0, 0, picCopy)
put " "
put " "
locate (35, 126)
put "PRESS ANY KEY TO CONTINUE"
locate (35, 126)
getch (key)
cls

end if
put ""
put "Alright, there should be a door, to get out, go to it"
put "*Fine but you better tell me whats going on here, and what is happening?*"
put "**You hear laughing, all in good time ", username, "."
put " "
put " "
locate (35, 126)
put "PRESS ANY KEY TO CONTINUE"
locate (35, 126)
getch (key)
cls
put ""
put "**As you approach the door, you stumble upon something, when you look closer you see its a knife**"
put "**Would you like to pick it up?**"
put "The commands for this situation are...."
put "Pick it up....................Yes"
put "Leave it......................Leave"
Pic.Draw (PIC_ID5, 0, 0, picCopy)
get command
cls
if command = "Yes" then
put ""
put "You pick up the knife..."
locate (35, 126)
put "PRESS ANY KEY TO CONTINUE"
locate (35, 126)
getch (key)
cls
put ""
put "YOU HAVE JUST FOUND THE KNIFE!!!"
put "Stats!"
put "This weapon gives you 5 attack and 1 defense"
put "The code for this weapon is knife1"
put "Write it down somewhere!!!!!!!!!!!"
locate (35, 126)
put "PRESS ANY KEY TO CONTINUE"
locate (35, 126)
getch (key)
cls
elsif command = "No" then
put ""
put "You decide to leave the knife thinking you are in no need of a knife whatsoever..."
locate (35, 126)
put "PRESS ANY KEY TO CONTINUE"
locate (35, 126)
getch (key)
cls
else
colorback (255)
cls
loop
color (0)
put " EEEEEEEEEEEEEEEEEE RRRRRRRRRRRRR RRRRRRRRRRRRR OOOOOOOOOOOOOO RRRRRRRRRRRRR"
put " EEEEEEEEEEEEEEEEEE RRRRRRRRRR RR RRRRRRRRRR RR OOOOOOOOOOOOOO RRRRRRRRRR RR"
put " EE RR RRR RR RRR OO OO RR RRR"
put " EE RR RRR RR RRR OO OO RR RRR"
put " EE RR RRR RR RRR OO OO RR RRR "
put " EEEEEEEEEE RRRRRRRRRR RRRRRRRRRR OO OO RRRRRRRRRR "
put " EEEEEEEEEE RRRRRRR RRRRRRR OO OO RRRRRRR "
put " EE RRRRRRRR RRRRRRRR OO OO RRRRRRRR "
put " EE RR RRR RR RRR OO OO RR RRR "
put " EE RR RRR RR RRR OO OO RR RRR "
put " EEEEEEEEEEEEEEEEEE RR RRR RR RRR OOOOOOOOOOOOOO RR RRR "
put " EEEEEEEEEEEEEEEEEE RR RRR RR RRR OOOOOOOOOOOOOO RR RRR"
put " "
put " "
end loop

end if
put ""
put "Alright now ", username, " now go outside the door, you should find yourself in a hallway"
put "**As you step out the door, you try to get your bearings...**"
locate (35, 126)
put "PRESS ANY KEY TO CONTINUE"
locate (35, 126)
getch (key)
cls
colorback (255)
cls
Pic.Draw (PIC_ID6, 0, 0, picCopy)
cls
put "YOU HAVE JUST ENCOUNTERED YOUR FIRST MONSTER!!!!!!"
put "NOW YOU MUST BATTLE TO SURVIVE!!!!!!!!!!!!!"
locate (35, 126)
put "PRESS ANY KEY TO CONTINUE"
locate (35, 126)
getch (key)
cls
put "The stats for the 'head crab zombie' is...."
put "Attack...........................2"
put "Defense..........................1"
put "Would you like to battle this monster, or would you rather run away?"
put "You may gain some items from battling this monster, but if you run"
put "you may sustain damage..!"
locate (35, 126)
put "PRESS ANY KEY TO CONTINUE"
locate (35, 126)
getch (key)
cls
put "The commands for this situation are........"
put "Battle.............................Attack"
put "Run away like a coward.............Run"
get command
if command = "Attack" then
put "Now that you have chosen to attack the monster, you must select a weapon..."
put "When you picked up the knife from earlier on, you should have gotten a code..."
put "USE THAT CODE NOW!!!!"
locate (35, 126)
put "PRESS ANY KEY TO CONTINUE"
locate (35, 126)
getch (key)
cls
put "....Wait....You did pick up the knife didn't you?"
put "Well if you didn't I will give you the code...REMEMBER IT..."
locate (35, 126)
put "PRESS ANY KEY TO CONTINUE"
locate (35, 126)
getch (key)
cls
end if













































label "LEAVE" :
cls
put "What an unfortuanate desicion"
put " "
put " "
locate (35, 126)
put "PRESS ANY KEY TO CONTINUE"
locate (35, 126)
getch (key)
cls
put "**You hear a huge crackle, and hear a spark.**"
put " "
put " "
locate (35, 126)
put "PRESS ANY KEY TO CONTINUE"
locate (35, 126)
getch (key)
cls
put "**You stumble backwards and fall**"
put "**Unable to find the string again, you are forced to wander"
put "around the room aimlessly**"
put " "
put " "
locate (35, 126)
put "PRESS ANY KEY TO CONTINUE"
locate (35, 126)
getch (key)
cls
put "**Because there is no food or water, you die of malnutrition in a few days"
put "atleast, you think its a few days...**"
put " "
put " "
locate (35, 126)
put "PRESS ANY KEY TO CONTINUE"
locate (35, 126)
getch (key)
cls
put "GAME OVER....YOUR INABILITY TO TRUST HAS LED TO YOUR DEATH"
locate (35, 126)
put "PRESS THE ESC KEY TO EXIT!"
locate (35, 126)
getch (key)
if chars (KEY_ESC) then

Window.Close(death)
end if
cls
end case


Turing:


<Add your code here>



Please specify what version of Turing you are using
Version....4.1.1

Author:  xBalmungx [ Tue Jan 12, 2010 6:50 pm ]
Post subject:  Re: Glitch help in my program!

Oh, shoot, I forgot it was so long, my bad....but an update on details...I am currently in the middle of working on it, it is not finished, and this is a repost from another section, did not realize I could put it there, again Im sorry, Im new on this site

Author:  Ktomislav [ Wed Jan 13, 2010 9:37 am ]
Post subject:  Re: Glitch help in my program!

Everything is working till this two line:
Turing:
getch (key)
if chars (KEY_ESC) then


Can you figure out what is the problem here?

Author:  xBalmungx [ Wed Jan 13, 2010 5:26 pm ]
Post subject:  Re: Glitch help in my program!

Um, am I not supposed to use the getch command in this instance?

Author:  Ktomislav [ Wed Jan 13, 2010 5:58 pm ]
Post subject:  Re: Glitch help in my program!

Everything is fine except one word. Think harder and take look at the documentation. Wink

Author:  xBalmungx [ Wed Jan 13, 2010 6:02 pm ]
Post subject:  Re: Glitch help in my program!

I think its the chars in the brackets, because i really can't think of anything else lol

Author:  Ktomislav [ Wed Jan 13, 2010 6:13 pm ]
Post subject:  Re: Glitch help in my program!

OK I'll tell you what's the problem.
Well, you use chars variable to check if it is equal to ESC_KEY, but you should chect key variable..
I guess you just copied that from somewhere eh. Next time think harder.

Author:  xBalmungx [ Wed Jan 13, 2010 6:17 pm ]
Post subject:  Re: Glitch help in my program!

Well I didnt copy it from somewhere, I just sorta put it together from the documentation that came with turing, and what does a "chect key variable" mean?

Author:  Ktomislav [ Wed Jan 13, 2010 6:21 pm ]
Post subject:  Re: Glitch help in my program!

It means check. It's a typo..

Author:  xBalmungx [ Wed Jan 13, 2010 6:24 pm ]
Post subject:  Re: Glitch help in my program!

getch (key)
if chars (KEY_ESC) then

so, it should be
getch (key)
if chars (key) then????

or should it be
getch (KEY_ESC)
if chars (KEY_ESC) then

Author:  TheGuardian001 [ Wed Jan 13, 2010 6:29 pm ]
Post subject:  Re: Glitch help in my program!

Erm... Neither. You should be ignoring chars altogether, as array char of boolean is only useful with Input.KeyDown, which would be difficult to add in at this point.

You originally had:

Turing:

getch (key)
if chars (KEY_ESC) then


Is there a reason you decided to check the value of chars(KEY_ESCAPE)(which is a boolean variable you never assigned to) instead of the value of key, which is where you actually stored the value?

Author:  xBalmungx [ Wed Jan 13, 2010 6:32 pm ]
Post subject:  Re: Glitch help in my program!

Well, what I though basically was that in doing that code, when the user pressed the esc key, then the program would quit, but i think the documentation isnt that well detailed throughout Neutral

Author:  Ktomislav [ Wed Jan 13, 2010 6:32 pm ]
Post subject:  Re: Glitch help in my program!

You could try every single pissibility and you would know the answer. Well you wouldn't because you didn't write the every possibility. But you know what I mean.
Why don't you just take some time and think it through?? You people are unbelievable, you want everything served.
If you learn by heart then you should better not learn at all. It's just a waste of time..

Think about what I've just said before you reply.

EDIT: Sorry my fault, I never used getchar. I thought it is the same as Input.KeyDown. But everything else I said is still fine.
So the wrong part is that getch should be replaced with Input.KeyDown and key should be array char of boolean.

Author:  xBalmungx [ Wed Jan 13, 2010 6:59 pm ]
Post subject:  Re: Glitch help in my program!

getch (key)
if chars (KEY_ESC) then

okay so, if i understand you right, key should be an array char of boolean,
and getch should be replaced with input.keydown,
if i do that though, then what do i use with my other getch commands? because they all use the key command, btw i have only been doing turing for the past month....so yea

Author:  xBalmungx [ Wed Jan 13, 2010 7:03 pm ]
Post subject:  Re: Glitch help in my program!

OMG IM SOOOO FRUSTURATED. Mad

Author:  TerranceN [ Wed Jan 13, 2010 7:33 pm ]
Post subject:  Re: Glitch help in my program!

getch works like this:

Turing:
var input : string (1)

getch (input)

if (input = 'a') then
    put "b"
else
    put "c"
end if


Notice that this stops the program and waits for the user to press a key

Input.KeyDown() works like this:

Turing:
var input : array char of boolean

loop

    Input.KeyDown(input)
   
    if (input('a')) then
        put "b"
    else
        put "c"
    end if

end loop


Notice that it has to be looped because it does not wait for the user to press a key, instead it checks what keys are pressed the moment it is called.

You can use either method, but hopefully now you understand how they work.

Also, what if the user does not press escape? (just a hypothetical question to get you thinking about all the possibilities for input, I'm not looking for an answer)

Author:  Ktomislav [ Wed Jan 13, 2010 7:35 pm ]
Post subject:  Re: Glitch help in my program!

Turing:
Input.KeyDown (key)
if key (KEY_ESC) then
...
end if

Author:  xBalmungx [ Wed Jan 13, 2010 7:48 pm ]
Post subject:  Re: Glitch help in my program!

Well THANK YOU SOOOOOOOO MUCH OMG THAT ALMOST KILLED ME Razz
THAT HELPS SOOOo MUCH YESSSSSSSSSSSS
lol, um now I need help with a battle sequence in the program,

i was thinking of doing something with

the variables

var z:string <<<<Zombie/Monster
var z_maxhealth :int:=10<<<The zombies/monsters maximum health
var z_defense :int := 1 <<<<<The defense which will deduct your attack by its value
var z_attack :int := 2<<<<<<What the zombie/monster will hit you
var z_health:int<<<<Zombie/monster health after damage result
var maxHealth: int :=100<<<<Your maximum health
var health:int<<<Your health after damage result
var knife1:string<<<<The code for accessing the weapon
var knife1_att : int :=5 <<<< Your weapons attack, which will be deducted by the enemies defense, and will deduct the enemies health
var knife1_def:int :=1 <<<<<Defensive properties of the weapon, same as the monster/zombies defense
var damage:int<<<<<If necessary

Author:  TerranceN [ Wed Jan 13, 2010 8:18 pm ]
Post subject:  Re: Glitch help in my program!

For the battle sequence I would recommend using a function/procedure, if you don't know what that is check out Cervantes' Functions and Procedures Tutorial

This will allow you to to call it anytime (so you don't have to copy and paste large chunks of code over the place), and if you pass a boolean to it, you can choose whether to just show the results of the battle, or show turn by turn (I believe you asked for this in another thread, correct me if I'm wrong). Also, try to have the function not interfere with any global variables, so it could be easily reused if you ever make another project like this.

Almost all of those values could be either randomly generated in the function or passed to the function. Aim for something like this:

Turing:
% Parameters:
%---------------
% true, therefore only show results of battle
% health, to let the function know our health before the battle

% Return value: our health after the battle
health := RandomEncounter(true, health)


As for specifically how to code it, that is up to you.

Author:  xBalmungx [ Wed Jan 13, 2010 8:36 pm ]
Post subject:  Re: Glitch help in my program!

Do I have to use the function/procedure, or can i just write the code in it? I just really need an example to base my code off of, basically how a program would look like using those variables, I just need a "guide" if you will, I can figure out the rest and stuff

Author:  TheGuardian001 [ Wed Jan 13, 2010 8:48 pm ]
Post subject:  Re: Glitch help in my program!

You can write the code in, but then it would only happen once and only at a specific time...

As for a guide, Only you know what you want out of this. Write it out, step by step, in plain English, and then think of what you need to do to make Turing do that.

Author:  TerranceN [ Wed Jan 13, 2010 8:54 pm ]
Post subject:  Re: Glitch help in my program!

You could just write the code, but it could get kinda messy, and imo its always a good time to learn code organization, but its your choice.

I will help debug and fix what you write, but you have to write it. I am not going to create your program logic for you. My suggestion though is to start out really simple, maybe each turn decrease your health by one, but the enemies by 5 (so use constant values to start), and just use "enemy" for the name. Once you understand how to get that working, adding features will be much easier than trying to do it all at once.

Author:  xBalmungx [ Wed Jan 13, 2010 9:37 pm ]
Post subject:  Re: Glitch help in my program!

Alright so this is what I have so far, I have to go to sleep now, but, I think it's a good start. Didn't get a chance to test it though...

if command = "Attack" then
loop
z_health := z_maxhealth + z_defense - knife1_att
health := maxHealth + knife1_def - z_attack

put "Your sucessfully hit the enemy, and reduce his health to ",z_health,"."
put "The enemy has made a counter hit! and has reduced your health to ",health,"."
exit when z_health <=0
exit when health <=0
end loop
else
if command = "Rest" then
put "Rest"
end if
end if


: