Author Topic: CallClientFunction  (Read 1391 times)

JamesConway

  • Newbie
  • *
  • Posts: 39
  • Karma: +9/-3
    • View Profile
CallClientFunction
« on: April 05, 2015, 07:58:56 pm »
Hello guys,

I'm trying to show a gui when a person uses a specific command like this:

Code: [Select]
else if ( cmd == "help" )
{
     MessagePlayer("Showing help menu", player);
     CallClientFunc(player, "Scripts/Client/HelpGui.nut", "showGui");
     return 1;
}

Only it doesnt work. Also I'm not sure where the path leads from. Does it start from the root folder or from the scripts folder? The clien't function I'm calling does not need parameters.

Code: [Select]
function showGui()
{
Message( "Testing..." );

// We use VectorScreen to set the GUI position. When aligning to the center, we minus half the width/height.
    local pos = VectorScreen(ScreenWidth/2-245,ScreenHeight/2-50);
     
     // We use ScreenSize to set the GUI size.
    local size = ScreenSize(490,100);
     
     // Create the window with the title "Example Window", and declare it TheWindow
    TheWindow <- GUIWindow(pos,size,"Example Window");
     
     // Create a layer for our new window
     AddGUILayer(TheWindow);

return 1;
}

Many thanks

Theremin

  • Full Member
  • ***
  • Posts: 154
  • Karma: +48/-18
  • Worst Server Owner
    • View Profile
    • Visit my YouTube channel
Re: CallClientFunction
« Reply #1 on: April 05, 2015, 08:33:22 pm »
I'm not sure if anything else is wrong but the first thing I noticed is that you're writing "Scripts..." you don't need that, just start within the scripts subfolder hence it should be:
Code: [Select]
else if ( cmd == "help" )
{
     MessagePlayer("Showing help menu", player);
     CallClientFunc(player, "Client/HelpGui.nut", "showGui");
     return 1;
}
I checked Wiki example and even there it start declaring directly the folder inside Scripts folder. Declaring Scripts it's probably unneeded as of course any client function you'll be calling will certainly already be inside Scripts folder.

Anyway this is kinda OT, but perhaps you could directly use the command within a client script. I.e:
Code: [Select]
function onClientCommand( cmd, text )
{
if ( cmd == "help" )
{
Message( "Showing help menu" );
gui_code_here;
}
return 1;
}

JamesConway

  • Newbie
  • *
  • Posts: 39
  • Karma: +9/-3
    • View Profile
Re: CallClientFunction
« Reply #2 on: April 05, 2015, 08:37:29 pm »
Thanks, your second suggest would be fine in this case. I'm just trying to figure out on how to communicate between the server and client script and so far I'm not succeeding yet  :P
« Last Edit: April 05, 2015, 08:43:20 pm by JamesConway »

Theremin

  • Full Member
  • ***
  • Posts: 154
  • Karma: +48/-18
  • Worst Server Owner
    • View Profile
    • Visit my YouTube channel
Re: CallClientFunction
« Reply #3 on: April 05, 2015, 08:54:33 pm »
I see there is also onPlayerJoin event for client scripts, Though I never fiddled with that personally so I have no idea If it works in the same way as the server event does. But anyway did you try removing "Scripts/" from the code? and if yes, is the gui showing?

JamesConway

  • Newbie
  • *
  • Posts: 39
  • Karma: +9/-3
    • View Profile
Re: CallClientFunction
« Reply #4 on: April 05, 2015, 08:59:04 pm »
I tried it and It didn't* work. Ive tried various paths, but nothing. No errors either.
« Last Edit: April 05, 2015, 10:02:12 pm by JamesConway »

Vortrex

  • Full Member
  • ***
  • Posts: 267
  • Karma: +54/-73
    • View Profile
Re: CallClientFunction
« Reply #5 on: April 06, 2015, 07:47:11 pm »
Did you add the client script into Script.xml (located in the "Scripts/Client/" folder)?
Code: [Select]
<script file="HelpGui.nut" client="1" />

JamesConway

  • Newbie
  • *
  • Posts: 39
  • Karma: +9/-3
    • View Profile
Re: CallClientFunction
« Reply #6 on: April 06, 2015, 08:20:34 pm »
I got the paths mixed up. Instead of "Scripts/Client/blabla.nut" it should have been "Main/Client/blabla.nut". Thanks for all your suggestive replies!

 

© Liberty Unleashed Team.