Newbie scripter here and coder in general so bare with me.
I've been perusing through the wiki and also here on functions I'd want to use for a server I'm trying to make. I'm however greeted with the 'does not exist' error message to practically everything. Example this:
mySprite <- null;
function Script::ScriptLoad()
{
mySprite = GUISprite("Filename.png", VectorScreen(x, y));
}
Tried it, put it in client main.nut script in script folder, errors out that Script does not exist. Or say I do something like this:
CreateCheckpoint( null, 0, false, player.Pos, RGB(255, 0, 255), 2);
Put it in server-side script. The function doesn't exist.
I was under the impression that everything in the wiki or what's being said here is as easy as type the example and you're done, you should get something in-game. This is providing that you've harnessed all the plugins and declared their use in server.cfg. But these errors are throwing me off.
Is there something wrong on my end? Libraries not working or something? Or is it expected of me to define these functions. And if its expected of me to do such, how do these functions work with all these arguments in the syntax yet nothing in the function to process and if I'm to do that, why the wiki there saying those cuz basically you're free to make it any shit you like out of those function names, arguments and all and....yeah confused :)
mySprite <- null;
function Script::ScriptLoad()
{
mySprite = GUISprite("Filename.png", VectorScreen(x, y));
}
This code is of 04rell003 version and works only in 003, this doesn't work in 04rell004 versions because 004 have all those functions in Client-Side functions. And 003 have all those in Server-Side. You can choose 003 version but no update will be done in that version because that's old the newest and latest one is 04rell004 and for that you have to learn Client-Side stuff I know that's suux xd
Both the examples you gave are correct and should be working fine. Can you re-check your server version( for client-side scripts ) and re-download the plugins( for server-side plugin related problems )?
Are your plugins loading up correctly?
Is your version up to date (04rel004)?
I'm on 04rel004 and all my plugins are loading correctly. I just tried this and it worked.
function onPlayerJoin( player )
{
MessagePlayer("test", player);
}
So I guess my problem there was I didn't declare any of these functions beforehand. So like this one
CreateCheckpoint( null, 0, false, player.Pos, RGB(255, 0, 255), 2);
That's just how I had it throughout the entire document. I treated it as a built-in function that I didn't need to declare if you get me. But I guess I probably should've done this instead
function CreateCheckpoint(player, world, isSphere, pos, rgb, radius)
CreateCheckpoint( null, 0, false, player.Pos, RGB(255, 0, 255), 2);
So I'd presume on client-side that's also my issue. So how would I declare these GUI stuff? Cuz I've also tried this and it didn't work
my_textdraw <- ::GUILabel(VectorScreen(0, 256), Color(255, 255, 255), "Hello World");
It errors that the GUILabel doesn't exist
Quote from: GangstaRas on Oct 16, 2017, 01:29 PMmy_textdraw <- ::GUILabel(VectorScreen(0, 256), Color(255, 255, 255), "Hello World");
It errors that the GUILabel doesn't exist
remove the sign
//remove this sign >> ::
my_textdraw <- GUILabel(VectorScreen(0, 256), Color(255, 255, 255), "Hello World");
Quote from: zeus on Oct 16, 2017, 01:45 PMQuote from: GangstaRas on Oct 16, 2017, 01:29 PMmy_textdraw <- ::GUILabel(VectorScreen(0, 256), Color(255, 255, 255), "Hello World");
It errors that the GUILabel doesn't exist
remove the sign
//remove this sign >> ::
my_textdraw <- GUILabel(VectorScreen(0, 256), Color(255, 255, 255), "Hello World");
Made no difference. Same error
Server sided functions work on server sided scripts only, and vice versa for the client sided ones. There's no sense for it to not work unless you have properly loaded the plugins, make sure the syntax is correct, try populating your script from little onward, just like you messaged test at onPlayerJoin. Try to experiment more specifically which functions work and which do not, if one works, rest should too.
Alright, basically imagine the two files barebones like this:
Server-side:
dofile("store/script/main.nut");
Client-side:
my_textdraw <- GUILabel(VectorScreen(0, 256), Color(255, 255, 255), "Hello World");
And server.cfg is this:
plugins xmlconf04rel64 sqlite04rel64 squirrel04rel64 announce04rel64 ini04rel64 mysql04rel64 sockets04rel64 hashing04rel64
Listed everything even if its unnecessary.
Not a single line more in either script files though, imagine that. You guys are saying that this should absolutely work without declaring anything?
Don't load that file using your server. They'll be/should be downloaded and executed by the client, not by the server. Remove the dofile and it should work just fine.
I see, thanks for that. But then how do you test that your client code isnt rubbish? Just trial and error ingame?
You could use this:
http://forum.vc-mp.org/?topic=2765.0
You could also wrap your code in try {} catch() and print the error if it encounters.
function Script::ScriptLoad()
{
try
{
mySprite = GUISprite("Filename.png", VectorScreen(x, y));
}
catch(error)
Console.Print("Error encountered in Script::ScriptLoad() " + error );
}
Quote from: aXXo on Oct 16, 2017, 06:12 PMYou could use this:
http://forum.vc-mp.org/?topic=2765.0
You could also wrap your code in try {} catch() and print the error if it encounters.
function Script::ScriptLoad()
{
try
{
mySprite = GUISprite("Filename.png", VectorScreen(x, y));
}
catch(error)
Console.Print("Error encountered in Script::ScriptLoad() " + error );
}
Nice, this particular code though (filled out the parameters) gave me the error " trying to set 'class' "
Quote from: GangstaRas on Oct 16, 2017, 07:49 PMQuote from: aXXo on Oct 16, 2017, 06:12 PMYou could use this:
http://forum.vc-mp.org/?topic=2765.0
You could also wrap your code in try {} catch() and print the error if it encounters.
function Script::ScriptLoad()
{
try
{
mySprite = GUISprite("Filename.png", VectorScreen(x, y));
}
catch(error)
Console.Print("Error encountered in Script::ScriptLoad() " + error );
}
Nice, this particular code though (filled out the parameters) gave me the error " trying to set 'class' "
You'd probably have to declare that mysprite somewhere. Just add local mysprite = null; to the top of your script.
Quote from: GangstaRas on Oct 16, 2017, 07:49 PMQuote from: aXXo on Oct 16, 2017, 06:12 PMYou could use this:
http://forum.vc-mp.org/?topic=2765.0
You could also wrap your code in try {} catch() and print the error if it encounters.
function Script::ScriptLoad()
{
try
{
mySprite = GUISprite("Filename.png", VectorScreen(x, y));
}
catch(error)
Console.Print("Error encountered in Script::ScriptLoad() " + error );
}
Nice, this particular code though (filled out the parameters) gave me the error " trying to set 'class' "
You have to change = to <- because you want to make a new slot. You'd also want to prefix mySprite with :: so that it makes that slot in the root table, not in the class Script.
Quote from: GangstaRas on Oct 16, 2017, 07:49 PMQuote from: aXXo on Oct 16, 2017, 06:12 PM...
Nice, this particular code though (filled out the parameters) gave me the error " trying to set 'class' "
Welcome to VCMP client side scripting. Just for a brief explanation, the client side script itself is a huge class scope, I believe SLC had already pointed this out and it was supposed to be fixed but I guess it didn't happen. Basically either declare local vars on top or declare global vars and prefix with ::
Quote from: Thijn on Oct 17, 2017, 06:39 AMQuote from: GangstaRas on Oct 16, 2017, 07:49 PMQuote from: aXXo on Oct 16, 2017, 06:12 PMYou could use this:
http://forum.vc-mp.org/?topic=2765.0
You could also wrap your code in try {} catch() and print the error if it encounters.
function Script::ScriptLoad()
{
try
{
mySprite = GUISprite("Filename.png", VectorScreen(x, y));
}
catch(error)
Console.Print("Error encountered in Script::ScriptLoad() " + error );
}
Nice, this particular code though (filled out the parameters) gave me the error " trying to set 'class' "
You'd probably have to declare that mysprite somewhere. Just add local mysprite = null; to the top of your script.
Nah that still errored out, IceFlake method seemed to work instead
But thanks for the advice guys, I think this wraps it up until I get stuck again, but I should be able to make stuff now with all this info