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

Username:   Password: 
 RegisterRegister   
 battles in an rpg
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
diablo




PostPosted: Thu Nov 18, 2004 11:15 am   Post subject: battles in an rpg

i am making an RPG an my code is *almost* finished
but when i merged all my programs *(i did each individual area(battle,locations, shopping,etc) in their own mini-program)* it ran okay..for the most part.
my code is as follows for the problem:
code:
procedure castleofbarbaotem
    var gen4health : int
    var gen4atk : int
    var gen4def : int
    put "you are wandering in the Castle Of Barbaotem"
    put "when you suddenly encounter..."
    delay (2500)
    randint (num4, 1, 20)
    if (num4 = 1) then
        put " ...Doom Gaurd! "
        enemyhealth := 200
        enemyatk := 80
        enemydef := 80
        battle<-----(battle is a procedure)

then it will go to the battle procedure(which is before all the areas)
and it says (when i make the choice to fight), that the enemy health variable has no value.....


can you tell me what i did wrong?
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Thu Nov 18, 2004 12:28 pm   Post subject: (No subject)

my guess is that that variable is decleared localy to some function. You will not be able to access it from other areas unless it is made global (decleared outside of a function, such as beginning of the program)
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Delos




PostPosted: Thu Nov 18, 2004 4:16 pm   Post subject: (No subject)

Or you could just change the way your 'battle' procedure works to include parameters...

code:

battle (200, 80, 80, myHero.health, myHero.atk, myHero.def)


Which would corespond to the relevant pieces of info needed...then during 'battle', you just refer back to them!

Something like:
code:

procedure battle (enHel, enAtk, enDef, userHel, userAtk, userDef : int)
% Note that since they're ints, you can't modify them...you could
% make them var ... : ints then you could, but then you'd only
% be able to use vars in the parameters.

% Code goes here...
userHel -= (enAtk - userDef)
% etc etc.


Easy as pi.
diablo




PostPosted: Fri Nov 19, 2004 1:35 pm   Post subject: (No subject)

my code goes as follows:
code:
   loop

        delay (3000)
        put "your encounter with one of  my minions will be your last!"
        delay (2000)
        put "what will you do?"
        put "1=fight,2=run(running takes away XP),3=item,4=magic"
        get choice
        if (choice = 1) then
            randint (damage, 1, 10)
            if (damage = 10) then
                enemydamage := (atk * 1.15) - enemydef
                put "you dealt, ", enemydamage, " to the enemy!"
    enemyhealth := enemyhealth - enemydamage<--(this has no value)
%etc,etc

and when i tried your suggestions,they didnt work at all!
dont get me wrong i appreciate them
then i tried to declare them all globally, they didnt work then
and then i thought:
the program has already read "battle" and knows what it does,
so here i am in a procedure, calling a procedure.........
so how do i go about calling battle ( procedure) from areaX(also a procedure)
Delos




PostPosted: Fri Nov 19, 2004 4:35 pm   Post subject: (No subject)

There's nothing wrong with calling a procedure from within another procedure, just so long as the one being called has previously been declared (this sort of thing is not an issue in more advanced languages).

You may want to have a look in the Tutorials section at the ones on Procedures...might be of some help.

Procedures Functions Processes by tony
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  [ 5 Posts ]
Jump to:   


Style:  
Search: