<!--quoteo(post=144188:date=Mar 31 2006, 09:03 PM:name=kblack)--><div class='quotetop'>QUOTE(kblack @ Mar 31 2006, 09:03 PM) [snapback]144188[/snapback]</div><div class='quotemain'><!--quotec-->
lets suppose that in Ships / Ships.c I declare a new attribute...
... mchref.ship.stats.goodsails=1;
Now in ShipUpdateParameters I wanna to check it... can I?
And how? Can I directly test mchref.ship.stats.goodsails? Or first I have to declare a local ref and then "load"them with GetCharacter or GetMainCharacter ?
<!--QuoteEnd--></div><!--QuoteEEnd-->
What the referencevariable(I think you call that also an object) mchref stands for must be declared in each function anew. E.g. <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->ref mchref = GetMainCharacter()<!--c2--></div><!--ec2--> would make it a reference to the playercharachter.
Make sure that the function where you want to declare your goodsails attribute already has some reference to the playercharachter. It must not be mchref, Akella used a lot of other playerrefs: pchar, mch, mc, mchar...
Once you have declared your mchref.ship.stats.goodsails=1 you can call it anywhere in the game IF you use the correct reference to the player.
void Ship_UpdateParameters() in AIShip.c has no playerreference yet, so you must make one:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->
ref mchref = GetMainCharacter();
Logit(mchref.ship.stats.goodsails);<!--c2--></div><!--ec2-->would display "1" on the screen, given that you assigned that text in ships.c. (Remember, attributes are always text, even mchref.ship.stats.goodsails=1).
You don't have to use mchref again,
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->
ref pchar = GetMainCharacter();
Logit(pchar.ship.stats.goodsails);<!--c2--></div><!--ec2-->would also work.
<!--quoteo--><div class='quotetop'>QUOTE</div><div class='quotemain'><!--quotec-->If I define in Ships.c a variable as:
checkedgoodsails=0;
Can I "see" this variable from other function? Do I have something like "global" variables?
<!--QuoteEnd--></div><!--QuoteEEnd-->
FAIK such a variable works only in the function where it was declared, so it may not work everywhere. You can declare global variables with #define, like e.g. all the tweaks in buildsettings.h:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->
#define FIRSTNAME "Nathaniel"<!--c2--></div><!--ec2-->But Nathan taught to use as few global variables as possible(can't remember the reasons, only that he posted that on www.thelib.com in autumn 2003, my first hard lesson in coding <img src="style_emoticons/<#EMO_DIR#>/icon_mrgreen1.gif" style="vertical-align:middle" emoid="
" border="0" alt="icon_mrgreen1.gif" /> )
So attributes should be the preferred method to store data that you want to use elsewhere in the game (Akella preferred the as well, as you have surely already noticed <img src="style_emoticons/<#EMO_DIR#>/smile.gif" style="vertical-align:middle" emoid="
" border="0" alt="smile.gif" /> )
Tired, confused? If not, lets go back to void Ship_UpdateParameters() in AIShip.c . These two lines at the beginning:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->
int iCharacterIndex = GetEventData();
ref rCharacter = GetCharacter(iCharacterIndex);<!--c2--></div><!--ec2-->
declare that rCharacter refers to the "captaincharacter" of the ship we are dealing with. This must not be the maincharacter, it can be any NPC with a ship. But further is a section that runs only if rCharacter IS the player:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->
if(iCharacterIndex == GetMainCharacterIndex())
{
.....<!--c2--></div><!--ec2-->So after that check you could use rCharacter as reference to the maincharacter:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->
if(iCharacterIndex == GetMainCharacterIndex())
{
Logit(rCharacter.ship.stats.goodsails);
int goodsailsvar = sti(rCharacter.ship.stats.goodsails);
<!--c2--></div><!--ec2-->would display "1" on the screen, given that you assigned mchref.ship.stats.goodsails=1 in ships.c.
And the new integer variable goodsailsvar would get the VALUE 1, converted from the TEXT "1" of the attribute. So now you can use goodsailsvar to do calculations WITHIN the current function.
HTH <img src="style_emoticons/<#EMO_DIR#>/smile.gif" style="vertical-align:middle" emoid="
" border="0" alt="smile.gif" />