Author Topic: loop on bottom print dosnt work  (Read 1643 times)

Ok with this code works almost perfect it displays %client.Wallet but the loop does not keep it updated why?

Code: [Select]
package walletDisplay
{
function gameConnection::onClientEnterGame(%client)
{


cancel($mySchedule);

%count = clientGroup.getCount();

for(%i = 0; %i < %count; %i++)
{
%client = clientGroup.getObject(%i);

commandToClient(%client, 'bottomPrint', %client.DisplayText, -1, true);
}

$mySchedule = schedule(1, 0, DisplayText);
Parent::onClientEnterGame(%client);
}
};
activatepackage(walletDisplay);


function serverCmdTest(%client)
{
%client.Wallet -= 500;
echo(%client.Wallet);
}

Code: [Select]
package DisplayText
{
function gameConnection::onClientEnterGame(%client)
{
%DisplayFont = "<font:impact:27>";
%client.DisplayText = %DisplayFont;
%client.Wallet = 1500;


if(%client.Wallet > 0)
%client.DisplayText = %client.DisplayText SPC "Money: $" @ %client.Wallet;

Parent::onClientEnterGame(%client);
}

};
activatepackage(DisplayText);


You're telling schedule to call the function DisplayText() which doesn't exist in any of the code you provided

That's the main thing you're noticing but there's multiple other things you'll notice (your method of setting displaytext won't work as your expect it to) bit I don't have time to address them at the moment
« Last Edit: April 29, 2015, 08:55:13 AM by Headcrab Zombie »

« Last Edit: April 29, 2015, 07:48:28 PM by -Setro- »


Post your updated code with the fixed schedule then. Also what you did makes it so every time someone spawns it will update everyone's HUD instead of just the guy who spawned.
You're also overwriting the %client variable set when the function is called with the last person in the clientGroup object so it could possibly break stuff when you parent with it.

I retyped it and it works better but it would display %client.Wallet
Code: [Select]
%DisplayFont = "<font:impact:32>";
%client.Wallet = 1500;
%client.DisplayText = %DisplayFont;

package TextDisplay
{
function gameConnection::TextDisplay(%client)
{

if(%client.Wallet > 0)
%client.DisplayText = %client.DisplayText SPC "$" @ %client.Wallet;

Parent::onClientEnterGame(%client);

}

};
activatePackage(TextDisplay);



function walletDisplay(%client)
{

cancel($mySchedule);

%count = clientGroup.getCount();

for(%i = 0; %i < %count; %i++)
{
%client = clientGroup.getObject(%i);

commandToClient(%client, 'bottomPrint', %client.DisplayText, 0, true);
}

$mySchedule = schedule(1, 0, walletDisplay);
}


function serverCmdTest(%client)
{
%client.Wallet -= 500;
echo(%client.Wallet);
}

Change the function name in the package to gameConnection::onClientEnterGame.

Remove the local variables on top of your code, as they will do absolutely nothing. Never put local variables outside of a function. It can mess things up. You can define those local variables in gameConnection::onClientEnterGame if you wish.

Remove the %client argument from function walletDisplay. You're not even doing anything with it, so why have it?

Change $mySchedule to something less generic, as I obviously intended you to do when I gave you the example.
« Last Edit: May 03, 2015, 07:25:54 AM by jes00 »

In addition to jes' fixed:

your method of setting displaytext won't work as your expect it to
This still applies
You're not putting a placeholder for the variable in there, you're putting the actual value of it.
So if %client.wallet is equal to 1500, then displayText will be set to "<font:impact:32>$1500", and it will never change from that because you never update displayText
(This example assumes %client.wallet is given a value, which it never is in your code. Jes' second fix will fix that)
Get rid of displayText and change the reference to it in the bottom print call to "<font:impact:32>" @ %client.wallet

Formatting/Indentation. Learning how to do it properly will make your code several times more readable

Nothing it currently calling walletDisplay(). Since the function looks through every client, don't do it on client join. It only needs to be called once. I'd find some function that activates when the server starts, and call it there.

The time argument for schedule is in milliseconds, not seconds. Your trying to update it every millisecond. That's one thousand times per second. That's unreasonable. Change the 1 in schedule to 1000.
« Last Edit: May 03, 2015, 10:43:19 AM by Headcrab Zombie »

Change the function name in the package to gameConnection::onClientEnterGame.

Remove the local variables on top of your code, as they will do absolutely nothing. Never put local variables outside of a function. It can mess things up. You can define those local variables in gameConnection::onClientEnterGame if you wish.

Remove the %client argument from function walletDisplay. You're not even doing anything with it, so why have it?

Change $mySchedule to something less generic, as I obviously intended you to do when I gave you the example.
1 question, I used %client.Wallet so if I take out the %client argument out will that make it where I can no longer use % client.Wallet I intended on having it seprate functions

Slightly OT but there's no need to send it to the client every millisecond. It's also probably more efficient to call the update whenever a transaction takes place