Game Development Community

Gold not increasing

by Martyn · in Torque Game Builder · 04/04/2009 (7:45 pm) · 2 replies

Hello

Im working on a simple script where the player collects coins and the Gui increases by one each time they pick one up.

I have it working so that when I walk onto a coin it adds to 1 but as soon as I walk over the 2nd the amount does not increase. I have been looking at the script and can not work out why!

Would you guys mind taking a look to see if im missing something;

The Script below is for the actual Coin object

function Gold::onCollision(%this, %dstObj)
{
if(%dstObj.class $= "PlayerDragon")
{
%this.GoldCollectedCount = %this.GoldCollectedCount ++;
GuiGoldCollected.text = "Gold:" SPC %this.GoldCollectedCount;

%this.spawn();
}

}

function Gold::spawn(%this)
{
%this.safedelete();
}

Now the below script is for the actual level - controlling the GUI

function LevelOne::onLevelLoaded(%this, %scenegraph)
{
%this.GoldCollectedCount = 0;

GuiGoldCollected.text = "Gold:" SPC %this.GoldCollectedCount;
}


Thank You :)

About the author

I have been interested in game development for around 10 years, it has always remained a hobby. I am now looking to develop my skills and maybe progress it from a hobby into a 2nd income.


#1
04/04/2009 (9:29 pm)
Looks like %this is the gold itself. Why not track the gold collected in the "PlayerDragon" instead?

From the scripts, if %this is the gold, then what might be happening is that gold may increment one when it's hit, and then another is spawned and initialized at 0, resetting the score, so you won't even see it go from 0 to 1 and back to 0.

If you track the variable inside the "PlayerDragon", then it doesn't get respawned/reinitialized, and should show correctly. So that line:

%this.GoldCollectedCount = %this.GoldCollectedCount ++;
GuiGoldCollected.text = "Gold:" SPC %this.GoldCollectedCount;

Should be:

%dstObj.GoldCollectedCount = %dstObj.GoldCollectedCount ++;
GuiGoldCollected.text = "Gold:" SPC %dstObj.GoldCollectedCount;

And %this should be replaced everywhere else applicable with a variable pointing to the player object.

Of course, if I'm wrong, I blame the fact that it's half-past midnight here ;)
#2
04/04/2009 (9:51 pm)
Thanks - currently 5:52 am here, hoping to get some things done on this game hehe