Low Caliber Forum
Another small code problem

This topic can be found at:
http://lowcaliber.com/eve/forums/a/tpc/f/3886011002/m/7026006234

Sun September 21 2003, 01:38 AM
Methril
Another small code problem
What would be the best way to increment a variable by 1 when the picked up function is called?

I've been trying

Gold = Gold + 1;
and
Gold + 1 = GoldTotal
but they are not working.

I'm sure a local variable will work for saying the ammount of gold you carry, but will it also work if say I had a zoneinfo that had an if statement for a certain amount of gold being carried.
Sun September 21 2003, 01:49 AM
Unter den Uebrigen
Gold++;
Some context would help.
Sun September 21 2003, 01:50 AM
Methril
Eek how could I not remember this?



**falls over**
Tue September 23 2003, 08:00 PM
Methril
Not working. No matter how many you pickup it always says you have 1 coin only.
==================================================
//Pickup function
function PickupFunction(Pawn Other)
{
local int Gold;
local string PlayerName;
local RunePlayer Player;
Player = RunePlayer(Other);
PlayerName = Player.PlayerReplicationInfo.PlayerName;

Gold++;

//the BroadcastMessage with current gold ammount

BroadcastMessage(" "$PlayerName$" has "$Gold$" gold coins." ,false ,'Subtitle');

}
==================================================
Wed September 24 2003, 02:10 PM
Unter den Uebrigen
Originally posted by Methril:
local int Gold;
You've declared it locally; it will therefore initialize to zero with each call of the function.  Declare it, rather, at the top of your class with a
var int Gold;

Wed September 24 2003, 05:14 PM
Methril
it doesnt work

It does not work doing the exact same thing it was doing before. Staying as 1.


Wed September 24 2003, 06:39 PM
Dante
seems appropriate here to try a few "if...else..." lines?
will rune allow this? cumbersome and with heavy nwn "accent":
int nCount=GetLocalInt(RunePlayer, "GOLD_COUNT");
{
nCount = nCount+1;
if (nCount==1)
{
BroadcastMessage("RunePlayer has 1 gold coin.");
}
else
{
BroadcastMessage("RunePlayer has "+IntToString(nCount)+" coins.")
}
SetLocalInt(RunePlayer, "GOLD_COUNT", nCount);
}

in any case the above surely needs more parameters..please en-fleshen?
i'm captivated by the elegance of 'var' though - i'll research it.


Wed September 24 2003, 08:15 PM
Methril
Interesting, but don't you think it's a bit over the top? I mean we are just adding to one variable and then displaying it when the function is called. Maybe I just don't know what im doing.
Cool
Thu September 25 2003, 06:32 PM
Unter den Uebrigen
Originally posted by Methril:
It does not work doing the exact same thing it was doing before. Staying as 1.
It looks like you're declaring the function in the gold piece itself; if that's the case, for each new gold piece you pick up the number will always be initialized to zero and return as one.

Declare the variable in your pawn class and have each pawn store their own gold information.  The call would then be, for instance:
myPlayerPawn(Other).Gold++;
BroadcastMessage(PlayerName @ "has" @ myPlayerPawn(Other).Gold @ "gold coins.", false, 'Subtitle');