Author Topic: Error in Script  (Read 2048 times)

       
Whats wrong with this? I think it has to do with the kill function because whenever Health is <= 0 and %this.kill() is there it crashes my game.

Code: [Select]
         function AIPlayer::checkAlive(%this)
        {
                        if(!isObject(%this))
                                return;
                        if(%this.Health <= 0)
                        {
                                %this.Health = 0;
%this.kill();
                        }
        }

can we see all your code

You're clearly doing this in something related to damage, which means that the instant you .kill() the bot (damaging it), you go into that same function and call this function again.
Infinite loop, and then Blockland crashes due to a stack overflow.

So how would I kill the bot and not get that error?

Well, you could learn to code properly so that kind of thing can't happen, but without knowing the damage function itself, the only fix I can tell you how to do is to check if the bot is alive.

Code: [Select]
         function AIPlayer::checkAlive(%this)
        {
                        if(!isObject(%this) || %this.getState() $= "DEAD")
                                return;
                        ...
        }


I have one more question. I'm making this HUD and whenever the number of Plastic the player has gets above 100 it will disappear and reappear randomly whenever it adds or subtracts. Whats the problem there?
« Last Edit: November 25, 2013, 02:45:21 PM by xXDeadwolf456Xx »

I have one more question. I'm making this HUD and whenever the number of Plastic the player has gets above 100 it will disappear and reappear randomly whenever it adds or subtracts
That's not a question.

I have one more question. I'm making this HUD and whenever the number of Plastic the player has gets above 100 it will disappear and reappear randomly whenever it adds or subtracts
That's not a question.

This is coding help. If you need help with your code, you need to post it

We aren't gods. We can't take a vague problem and pinpoint it with a specific solution. It's like calling someone when you've been teleported to a random location on the Earth and saying "Where am I? I see a bunch of grassy fields..."

Client:

Code: [Select]
function clientCmdUpdateVars(%Exp, %NeedExp, %Level, %Plastic, %Copper, %Iron, %Gold, %Platinum, %Reetor, %CopperBars, %IronBars, %GoldBars, %PlatinumBars, %ReetorBars, %HP, %MAXHP, %MAGIC, %MAXMAGIC)
{
HealthBar.extent = mFloor(%HP*2) SPC "15";
MagicBar.extent = mFloor(%MAGIC*2) SPC "15";
Plastic.setText("<font:impact:18>Plastic: " @ %Plastic);
}


Server:

Code: [Select]
/////////////
//Run Loop//
///////////

package ClientEnterGame
{

     function GameConnection::onClientEnterGame(%client)
     {
  parent::onClientEnterGame(%client);
  %client.startTaskLoop();
}

function GameConnection::SpawnPlayer(%client)
{
parent::SpawnPlayer(%client);
%client.startTaskLoop();
}


function gameconnection::startTaskLoop(%client)
 {
    cancel(%client.TaskLoop);
%file = new FileObject();
    %filename = "config/server/ReeRPG/" @ %client.bl_id @ ".txt";
    %file.openForWrite(%filename);
    %file.writeLine(%client.exp);
    %file.writeLine(%client.needexp);
    %file.writeLine(%client.level);
    %file.writeLine(%client.Plastic);
%file.writeLine(%client.Health);
%file.writeLine(%client.MaxHealth);
%file.writeLine(%client.Magic);
%file.writeLine(%client.MaxMagic);
    %file.close();
    %file.delete();



%Exp = %client.exp;
%NeedExp = %client.needexp;
%Level = %client.level;
%Plastic = %client.Plastic;

%Copper = %client.Copper;
%Iron = %client.Iron;
%Gold = %client.Gold;
%Platinum = %client.Platinum;
%Reetor = %client.Reetor;

%CopperBars = %client.CopperBars;
%IronBars = %client.IronBars;
%GoldBars = %client.GoldBars;
%PlatinumBars = %client.PlatinumBars;
%ReetorBars = %client.ReetorBars;

%HP = %client.Health;
%MAXHP = %client.MaxHealth;
%MAGIC = %client.Magic;
%MAXMAGIC = %client.MaxMagic;
commandToClient(%client,'UpdateVars',%Exp, %NeedExp, %Level, %Plastic, %Copper, %Iron, %Gold, %Platinum, %Reetor, %CopperBars, %IronBars, %GoldBars, %PlatinumBars, %ReetorBars, %HP, %MAXHP, %MAGIC, %MAXMAGIC);
%client.TaskLoop = %client.schedule(100, startTaskLoop);
}

};
ActivatePackage(ClientEnterGame);

Well, since you still haven't told us what the problem is, I'm gonna guess that it's your client command. I believe there's a limit for number of arguments on functions, and even if it wasn't, that'd be an ugly way to do it. Turn it into a client command to send a name and value for a single variable, then just call it for each of your variables.

So why exactly are you running this stupid loop 10 times a second instead of telling the client when a value is changed

So why exactly are you running this stupid loop 10 times a second instead of telling the client when a value is changed
Didn't even notice that one. Surprisingly well written loop, though. Most people never think to cancel it to prevent repeats (which he'd certainly have due to calling it every time the player spawns), and making it a method of a client is nice. Too bad the atrocious indentation, ambiguous naming, and inconsistent capitalization of "GameConnection" leave his coding conventions far from perfect.

forget it the MLTextCtrl was to short.