Vice City: Multiplayer

VC:MP Discussion => Support => Topic started by: GangstaRas on Oct 15, 2017, 11:47 PM

Title: Help with function library
Post by: GangstaRas on Oct 15, 2017, 11:47 PM
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 :)
Title: Re: Help with function library
Post by: SAzEe21 on Oct 16, 2017, 05:55 AM
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
Title: Re: Help with function library
Post by: KAKAN on Oct 16, 2017, 06:30 AM
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 )?
Title: Re: Help with function library
Post by: Xmair on Oct 16, 2017, 01:23 PM
Are your plugins loading up correctly?
Is your version up to date (04rel004)?
Title: Re: Help with function library
Post by: GangstaRas on Oct 16, 2017, 01:29 PM
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
Title: Re: Help with function library
Post by: ! on Oct 16, 2017, 01:45 PM
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");

Title: Re: Help with function library
Post by: GangstaRas on Oct 16, 2017, 02:19 PM
Quote from: zeus on Oct 16, 2017, 01:45 PM
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");



Made no difference. Same error
Title: Re: Help with function library
Post by: DizzasTeR on Oct 16, 2017, 02:48 PM
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.
Title: Re: Help with function library
Post by: GangstaRas on Oct 16, 2017, 04:30 PM
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?
Title: Re: Help with function library
Post by: KAKAN on Oct 16, 2017, 04:56 PM
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.
Title: Re: Help with function library
Post by: GangstaRas on Oct 16, 2017, 05:49 PM
I see, thanks for that. But then how do you test that your client code isnt rubbish? Just trial and error ingame?
Title: Re: Help with function library
Post by: aXXo on Oct 16, 2017, 06:12 PM
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 );
}
Title: Re: Help with function library
Post by: GangstaRas on Oct 16, 2017, 07:49 PM
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' "
Title: Re: Help with function library
Post by: Thijn on Oct 17, 2017, 06:39 AM
Quote from: GangstaRas on Oct 16, 2017, 07:49 PM
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' "
You'd probably have to declare that mysprite somewhere. Just add local mysprite = null; to the top of your script.
Title: Re: Help with function library
Post by: EK.IceFlake on Oct 17, 2017, 11:40 AM
Quote from: GangstaRas on Oct 16, 2017, 07:49 PM
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' "
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.
Title: Re: Help with function library
Post by: DizzasTeR on Oct 17, 2017, 11:54 AM
Quote from: GangstaRas on Oct 16, 2017, 07:49 PM
Quote 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 ::
Title: Re: Help with function library
Post by: GangstaRas on Oct 17, 2017, 03:28 PM
Quote from: Thijn on Oct 17, 2017, 06:39 AM
Quote from: GangstaRas on Oct 16, 2017, 07:49 PM
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' "
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