Computer Science Canada

classes help

Author:  evildaddy911 [ Tue May 08, 2012 10:43 am ]
Post subject:  classes help

What is it you are trying to achieve?
I'm trying to replicate the pokemon combat system, in the hopes that i can create a new game with it

What is the problem you are having?
when i use the initialize procedure of the character class, the player's data gets replaced by the enemy -> initialize parameters

Describe what you have tried to solve this problem
this is one of my first projects with classes, so i have no idea what is wrong

if anyone can help me clean up my code, it would be appreiciated too

Please specify what version of Turing you are using
open atm, the school has 4.0.5, my home has 4.1.1a

Author:  Dreadnought [ Tue May 08, 2012 12:47 pm ]
Post subject:  Re: classes help

evildaddy911 wrote:
when i use the initialize procedure of the character class, the player's data gets replaced by the enemy -> initialize parameters


I'm not sure what the expected behavior is. What is supposed to happen that is not happening, or what is happening that shouldn't?

Author:  evildaddy911 [ Tue May 08, 2012 2:54 pm ]
Post subject:  Re: classes help

on lines 223 and 224 (ive made some changes, so the old file may have this on different lines), i have
Turing:
player -> initialize ("player", Rand.Int (50, 200), Rand.Int (50, 200), Rand.Int (500, 2000), player -> get_xp, player -> get_lv) %   sets up random player/enemy stats
enemy -> initialize ("enemy", Rand.Int (50, 200), Rand.Int (50, 200), Rand.Int (500, 2000), enemy -> get_xp, enemy -> get_lv)

[ proc initialize (name : string, attack, defence : real, health, Exp, Level : int) ]
what is happening, is the second initialize call is overriding the first, giving both enemy and player identical stats. I dont want this, i want the player and enemy to have different stats. I thought that when you defined variables for one object, they would not alter another object of the same class's variables. I have no idea why this is happening, so im asking how to fix it

Author:  Zren [ Tue May 08, 2012 6:58 pm ]
Post subject:  RE:classes help

Turing:

    function get_attk : real
        result temp.Atk
    end get_attk

    function get_def : real
        result temp.Atk
    end get_def

Author:  evildaddy911 [ Thu May 10, 2012 3:06 pm ]
Post subject:  RE:classes help

thanks, fixed now


: