Low Caliber Club
Low Caliber Club
    Low Caliber Forum  Hop To Forum Categories  Work in Progress    Another small code problem

Moderators: Impaler, Mr_Fister
Go
New
Find
Notify
Tools
Reply
  
Another small code problem
 Login/Join
 
Peregrine
Picture of Methril
Online Status For 145666303
posted
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.
 
Posts: 15 | Location: Edmonton,Alberta,Canada | Registered: Mon September 15 2003Reply With QuoteReport This Post
Treasurer
Picture of Unter den Uebrigen
posted Hide Post
Gold++;
Some context would help.
 
Posts: 1457 | Location: Altadena | Registered: Tue January 07 2003Reply With QuoteReport This Post
Peregrine
Picture of Methril
Online Status For 145666303
posted Hide Post
Eek how could I not remember this?



**falls over**
 
Posts: 15 | Location: Edmonton,Alberta,Canada | Registered: Mon September 15 2003Reply With QuoteReport This Post
Peregrine
Picture of Methril
Online Status For 145666303
posted Hide Post
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');

}
==================================================
 
Posts: 15 | Location: Edmonton,Alberta,Canada | Registered: Mon September 15 2003Reply With QuoteReport This Post
Treasurer
Picture of Unter den Uebrigen
posted Hide Post
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;
 
Posts: 1457 | Location: Altadena | Registered: Tue January 07 2003Reply With QuoteReport This Post
Peregrine
Picture of Methril
Online Status For 145666303
posted Hide Post
it doesnt work

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

 
Posts: 15 | Location: Edmonton,Alberta,Canada | Registered: Mon September 15 2003Reply With QuoteReport This Post
Emeritus
Picture of Dante
posted Hide Post
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.

 
Posts: 1258 | Location: "Auslander" | Registered: Wed May 21 2003Reply With QuoteReport This Post
Peregrine
Picture of Methril
Online Status For 145666303
posted Hide Post
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
 
Posts: 15 | Location: Edmonton,Alberta,Canada | Registered: Mon September 15 2003Reply With QuoteReport This Post
Treasurer
Picture of Unter den Uebrigen
posted Hide Post
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');
 
Posts: 1457 | Location: Altadena | Registered: Tue January 07 2003Reply With QuoteReport This Post
  Powered by Social Strata  
 

    Low Caliber Forum  Hop To Forum Categories  Work in Progress    Another small code problem

© Low Caliber Club 2002-4
Gallery | Chat | Archive | Tutorials | Red Carpet

Constitution

Members

Forum

Stats

Wiki