Author Topic: Auto Loading Compass  (Read 718 times)

Trying to make a script to auto load the compass, I cannot figure out why it does not work, to errors.
Code: [Select]
//=========================================================================
// GUI Stuff
//=========================================================================
CompassWaypointGUI_File_Filename.delete();

CompassWaypointGUI_File.getObject(0).getObject(1).command = "CompassWaypointGUI.saveWaypointDelay();";
//Save button^^

CompassWaypointGUI_File.getObject(0).getObject(2).command = "CompassWaypointGUI.loadWaypointDelay();";
//Load button^^
//=========================================================================
// Functions
//=========================================================================
function CompassWaypointGUI::saveWaypointDelay()
{
%hostName = getSubStr($ServerInfo::Name, 0, strStr($ServerInfo::Name, "\'"));

%host = %host @ "'s server";

CompassWaypointGUI.saveWaypoints(%host);
}

function CompassWaypointGUI::loadWaypointDelay(%filename)
{
%hostName = getSubStr($ServerInfo::Name, 0, strStr($ServerInfo::Name, "\'"));

%host = %host @ "'s server";

if(isFile("config/client/WP/" @ %hostName @ "'s server.txt"))
CompassWaypointGUI.loadWaypoints(%host);
}

package Compass_Load
{
function serverConnection::onConnectionAccepted()
{
%host = getSubStr($ServerInfo::Name, 0, strStr($ServerInfo::Name, "\'"));


if(isFile("config/client/WP/" @ %host @ "'s server.txt"))
{
%filename = "config/client/WP/" @ %host @ "'s server.txt";

CompassWaypointGUI.loadWaypointDelay(%filename);
}

parent::onConnectionAccepted();
}
};
activatePackage(Compass_Load);

Debug, otherwise we won't find the problem.



Made him easier to understand
But that's kinda the point of the Coding Help topic; for when you can't "figure it out".

But that's kinda the point of the Coding Help topic; for when you can't "figure it out".
Add unique echoes so that you know what code is reached and what isn't.

What kalphiter said.

Code: [Select]
function testSomething()
{
echo("In Function!");

if(someTest()) {
echo("Pass 1");

if(someOtherTest())
{
echo("Pass 2");

while(doingSomething())
{
echo("Doing something!!!");
}
}
}
}

If you're not seeing proper output at say, Pass 2, then you know SomeOtherTest is breaking it.

This is a very sophisticated and high-level debugging technique. Use it carefully.

It only echos "Deleted GUI text box", "Changed save button command.", and "Changed load button command.".
Code: [Select]
//=========================================================================
// GUI Stuff
//=========================================================================
CompassWaypointGUI_File_Filename.delete();
echo("\c2Deleted GUI text box");

CompassWaypointGUI_File.getObject(0).getObject(1).command = "CompassWaypointGUI.saveWaypointDelay();";
echo("\c2Changed save button command.");
//Save button^^

CompassWaypointGUI_File.getObject(0).getObject(2).command = "CompassWaypointGUI.loadWaypointDelay();";
echo("\c2Changed load button command.");
//Load button^^
//=========================================================================
// Functions
//=========================================================================
function CompassWaypointGUI::saveWaypointDelay()
{
%hostName = getSubStr($ServerInfo::Name, 0, strStr($ServerInfo::Name, "\'"));

%host = %host @ "'s server";

CompassWaypointGUI.saveWaypoints(%host);
}

function LoadWaypointDelay(%filename)
{
%host = getSubStr($ServerInfo::Name, 0, strStr($ServerInfo::Name, "\'"));

echo("\c2Host = " @ %host);

if(isFile("config/client/WP/" @ %host @ "'s server.txt"))
{
echo("\c2LoadWaypointDelay: File found.");

CompassWaypointGUI.loadWaypoints(%host @ "'s server.txt");

echo("\c2CompassWaypointGUI.loadWaypoints called.");
}

else
{
echo("\c2LoadWaypointDelay: File not found.");
}
}

package Compass_Load
{
function serverConnection::onConnectionAccepted()
{
parent::onConnectionAccepted();

echo("\c2Connection accepted.");

%host = getSubStr($ServerInfo::Name, 0, strStr($ServerInfo::Name, "\'"));
echo("\c2Host = " @ %host);


if(isFile("config/client/WP/" @ %host @ "'s server.txt"))
{
%filename = "config/client/WP/" @ %host @ "'s server.txt";

echo("\c2File found: " @ %filename);

LoadWaypointDelay(%filename);

echo("\c2LoadWaypointDelay called.");
}

else
{
echo("\c2onConnectionAccepted: File not found.");
}
}
};
activatePackage(Compass_Load);

It only echos "Deleted GUI text box", "Changed save button command.", and "Changed load button command.".
Code: [Select]
//=========================================================================
// GUI Stuff
//=========================================================================
CompassWaypointGUI_File_Filename.delete();
echo("\c2Deleted GUI text box");

CompassWaypointGUI_File.getObject(0).getObject(1).command = "CompassWaypointGUI.saveWaypointDelay();";
echo("\c2Changed save button command.");
//Save button^^

CompassWaypointGUI_File.getObject(0).getObject(2).command = "CompassWaypointGUI.loadWaypointDelay();";
echo("\c2Changed load button command.");
//Load button^^
//=========================================================================
// Functions
//=========================================================================
function CompassWaypointGUI::saveWaypointDelay()
{
%hostName = getSubStr($ServerInfo::Name, 0, strStr($ServerInfo::Name, "\'"));

%host = %host @ "'s server";

CompassWaypointGUI.saveWaypoints(%host);
}

function LoadWaypointDelay(%filename)
{
%host = getSubStr($ServerInfo::Name, 0, strStr($ServerInfo::Name, "\'"));

echo("\c2Host = " @ %host);

if(isFile("config/client/WP/" @ %host @ "'s server.txt"))
{
echo("\c2LoadWaypointDelay: File found.");

CompassWaypointGUI.loadWaypoints(%host @ "'s server.txt");

echo("\c2CompassWaypointGUI.loadWaypoints called.");
}

else
{
echo("\c2LoadWaypointDelay: File not found.");
}
}

package Compass_Load
{
function serverConnection::onConnectionAccepted()
{
parent::onConnectionAccepted();

echo("\c2Connection accepted.");

%host = getSubStr($ServerInfo::Name, 0, strStr($ServerInfo::Name, "\'"));
echo("\c2Host = " @ %host);


if(isFile("config/client/WP/" @ %host @ "'s server.txt"))
{
%filename = "config/client/WP/" @ %host @ "'s server.txt";

echo("\c2File found: " @ %filename);

LoadWaypointDelay(%filename);

echo("\c2LoadWaypointDelay called.");
}

else
{
echo("\c2onConnectionAccepted: File not found.");
}
}
};
activatePackage(Compass_Load);
Your code runs when you join a server. Did you check then, or when you executed it? If you're getting nothing when you join a server, it's because serverConnection::onConnectionAccepted is the wrong function to parent. I'm not sure if it is or isn't. I think it is.