Author Topic: Chat messages not working anymore  (Read 1257 times)

Ha ha ha! You know what caused this whole chat message thing??? Script_RPChat




I am now having trouble with chat messages. It seems that I can't send any chat message to the client, whether it is in a package or not. This is how I make chat  messages:
Code: [Select]
%client.chatMessage("Looks like chat messages suddenly broke.");
If there is a problem with the code, please tell me.
The funny thing is that even when I type that in the console, like this:
Code: [Select]
function serverCmdcmt(%client){%client.chatMessage("Hello?");}
...it still doesn't work. Is this an error with v21 or what am I doing wrong?


Original post:

Yesterday, I made a script that had a GameConnection:: function inside it:
Code: [Select]
package spacerpserver
{
function GameConnection::onClientEnterGame(%client)
{
Parent::onClientEnterGame(%client);
%client.chatMessage("Welcome to \c3 Cowboy6's " @ $pref::server::name @ " ! \c6 This gamemode is custom-made by \c3 Hammereditor.");
bptoclient(%client);
%client.chatMessage("\c6 You can play with using commands such as /help, but download the client-sided script to have a cool GUI!");
%client.chatMessage("Sending chat messages requires \c4 Battery.\c0 It recovers over time, depending on your rank.");
}
};
activatePackage(spacerpserver);
...and it it didn't work. Other parts of my add-on didn't work, also, and when I removed the packages the functions were inside, everything kind of worked.
Somebody told me that you can't make functions with a Gameconnection:: parent outside of packages. Yet this package seems to be disabling the function. So I don't know what to do. If I remove the package, there will be a syntax error because game connections cant be outside packages. If I put it inside the pacakge, the function won't work. So what do I do?


Also, I'm having trouble with global variables. This doesn't work:
Code: [Select]
function t()
{
   $t = getRandom(1, 5);
}

function s()
{
   %r = $t;
}

I need to know how I can make a global variable inside a function, and use it inside another function. Does there have to be a package in between? Do they have to both be in a package? do they both have to be in the same package? Do they need to both be completely outside the package?

« Last Edit: August 16, 2012, 03:16:54 PM by hammereditor² »

With onClientEnterGame you should always return the parent and do it after the rest of the code

Code: [Select]
package spacerpserver
{
function GameConnection::onClientEnterGame(%client)
{
%client.chatMessage("Welcome to \c3 Cowboy6's " @ $pref::server::name @ " ! \c6 This gamemode is custom-made by \c3 Hammereditor.");
bptoclient(%client);
%client.chatMessage("\c6 You can play with using commands such as /help, but download the client-sided script to have a cool GUI!");
%client.chatMessage("Sending chat messages requires \c4 Battery.\c0 It recovers over time, depending on your rank.");
return Parent::onClientEnterGame(%client);
}
};
activatepackage(spacerpserver);

Since the update packages have been forgeted up so you might need to re execute it manually. This worked for me anyway when a package didn't activate

Also for the other function it would make more sense to do this

Code: [Select]
function s()
{
%r = getrandom(1,5);
}

With onClientEnterGame you should always return the parent and do it after the rest of the code

don't spread misinformation


Also for the other function it would make more sense to do this

Code: [Select]
function s()
{
%r = getrandom(1,5);
}
The reason I made t() and s() was to show you when I do that in the actual script, it doesn't work.

don't spread misinformation
But does what danny said at least work?

But does what danny said at least work?

returning the parent is not what fixed it

returning the parent is not what fixed it
I hought if you didn't return the parent the server would crash after a while?

returning the parent is not what fixed it
It never got fixed.

And what about my second problem, the one with the variables, and packages?

I hought if you didn't return the parent the server would crash after a while?

how would that even make sense

It never got fixed.

whoops, misread that post
returning the parent won't fix it, no

And what about my second problem, the one with the variables, and packages?

you can set global variables just fine in functions, regardless of whether they're in a package or not
t() wasn't evaluated earlier when you used s(), or the latter function doesn't use that variable for anything at all
you may also want to check out the return statement instead of transferring stuff over global variables

how would that even make sense
Was something I read on a coding help topic a few months ago by Kalphiter.

how would that even make sense

whoops, misread that post
returning the parent won't fix it, no

you can set global variables just fine in functions, regardless of whether they're in a package or not
t() wasn't evaluated earlier when you used s(), or the latter function doesn't use that variable for anything at all
you may also want to check out the return statement instead of transferring stuff over global variables
What does the
Code: [Select]
return statement do?
So far, I only know that it exits out of functions.

returning the parent is not what fixed it
So are you saying that Gameconnection:: functions never work in v21?
If they do work, how do I fix it?

So are you saying that Gameconnection:: functions never work in v21?
If they do work, how do I fix it?
Packages are apparently forgeted up, I had to re execute some files manually to get them to work and they did so give that a shot and see if it helps at all.

Packages are apparently forgeted up, I had to re execute some files manually to get them to work and they did so give that a shot and see if it helps at all.
I tried doing both
Code: [Select]
exec("Add-Ons/Gamemode_SpaceRPG/server.cs");  //this is where the gameconnection was located
And I tried activating the package from the console, but got this result:
Code: [Select]
activatePackage(spacerpserver); //what I typed
Package spacerpserver already active //what the console said
I tried rejoining the server and it still didn't send the chat messages, nor did it call the other function "bptoclient(%client);".

It works fine for me