Author Topic: GUI not working  (Read 986 times)

Code: [Select]
[code]I need to make a client-sided script that communicates with a server-sided script.
So, I made a 3-part structure of functions which involves a client-sided GUI, a client-sided script, and a server-sided script.
On the first try, none of these had any syntax errors:

GUI part
[code]
new GuiBitmapButtonCtrl() {
         profile = "BlockButtonProfile";
         horizSizing = "relative";
         vertSizing = "relative";
         position = "12 81";
         extent = "100 39";
         minExtent = "8 2";
         enabled = "1";
         visible = "1";
         clipToParent = "1";
         command = "srpcBuyIce()";
         text = "Buy Ice Crystals";
         groupNum = "-1";
         buttonType = "PushButton";
         bitmap = "./button1";
         lockAspectRatio = "0";
         alignLeft = "0";
         overflowImage = "0";
         mKeepCached = "0";
         mColor = "0 255 255 255";
            wrap = "0";
};
Client part
Code: [Select]
function srpcBuyIce(%gui)
{
%amt = srpc_creditamt.getValue();
commandToServer("buyice", %amt);
}
Server part: (Note that this part works perfectly when the client uses it by typing in "/" commands like /refreshprices.)
Code: [Select]

function serverCmdbuyice(%client, %amt)
{
echo("Buy request submitted. Type: Ice crystals. Buyer name: " @ %client.name @ " .");
if (%amt < 1)
{
%client.chatMessage("Transaction failed. Reason: You need to buy at least 1 Ice crystal.");
echo("Transaction refused. Reason: Client did not offer to trade 1 unit or above.");
return;
}
%orderprice = ($srp::icecrystalprice * %amt);
echo("Order Price: " @ %orderprice @ " .");
if (%client.score < %orderprice)
{
%client.chatMessage("Transaction failed. Reason: You do not have enough points.");
echo("Transaction refused. Reason: Client does not have enough score points.");
return;
}
%startscore = %client.score;
echo("Client starting score: " @ %startscore @ " .");
%startice = %client.icecrystal;
echo("Client starting ice crystals: " @ %startice @ " .");
%client.score = (%startscore - %orderprice);
echo("Client finishing score: " @ %client.score @ " .");
%client.icecrystal = (%startice + %amt);
echo("Client finishing ice crystals: " @ %client.icecrystal @ " .");
echo("Transaction completed.");
%client.chatMessage("You have bought \c3 " @ %amt @ " Ice crystals \c0 for \c3 " @ %orderprice @ " Points.");
}

When I pressed the button for buying ice, Blockland crashed.
So I tried skipping the client.cs entirely and making the button communicate directly with the server:

GUI part:
Code: [Select]
new GuiBitmapButtonCtrl() {
         profile = "BlockButtonProfile";
         horizSizing = "relative";
         vertSizing = "relative";
         position = "12 81";
         extent = "100 39";
         minExtent = "8 2";
         enabled = "1";
         visible = "1";
         clipToParent = "1";
         command = "commandToServer("buyice", srpc_iceamt.getValue())";
         text = "Buy Ice Crystals";
         groupNum = "-1";
         buttonType = "PushButton";
         bitmap = "./button1";
         lockAspectRatio = "0";
         alignLeft = "0";
         overflowImage = "0";
         mKeepCached = "0";
         mColor = "0 255 255 255";
            wrap = "0";
};
That had a syntax error. Here it is:

command = "commandToServer("buyice"##,## srpc_iceamt.getValue())";

Then I tried these configurations:
---------------------------------------------------------------------
client.cs
Code: [Select]
function srpcBuyIce(%gui)
{
%amt = srpc_creditamt.getValue();
commandToServer("buyice", %amt);
}

Gui
Code: [Select]
new GuiBitmapButtonCtrl() {
         profile = "BlockButtonProfile";
         horizSizing = "relative";
         vertSizing = "relative";
         position = "12 81";
         extent = "100 39";
         minExtent = "8 2";
         enabled = "1";
         visible = "1";
         clipToParent = "1";
         command = "commandToClient("srpcBuyIce");";
         text = "Buy Ice Crystals";
         groupNum = "-1";
         buttonType = "PushButton";
         bitmap = "./button1";
         lockAspectRatio = "0";
         alignLeft = "0";
         overflowImage = "0";
         mKeepCached = "0";
         mColor = "0 255 255 255";
            wrap = "0";
      };

Syntax error:

 command = "commandToClient("srpcBuyIce"##)##;";
--------------------------------------------------------------------------------------------------------
Then this:

client.cs:
Code: [Select]
function clientCmdsrpcBuyIce(%gui)
{
%amt = srpc_creditamt.getValue();
commandToServer("buyice", %amt);
}

Gui:
Code: [Select]
new GuiBitmapButtonCtrl() {
         profile = "BlockButtonProfile";
         horizSizing = "relative";
         vertSizing = "relative";
         position = "12 81";
         extent = "100 39";
         minExtent = "8 2";
         enabled = "1";
         visible = "1";
         clipToParent = "1";
         command = "commandToClient("srpcBuyIce");";
         text = "Buy Ice Crystals";
         groupNum = "-1";
         buttonType = "PushButton";
         bitmap = "./button1";
         lockAspectRatio = "0";
         alignLeft = "0";
         overflowImage = "0";
         mKeepCached = "0";
         mColor = "0 255 255 255";
            wrap = "0";
      };
I know that the buy ice function is supposed to have an argument in it. I just wanted to see if the syntax error would go away when I removed the getValue thingy.
Syntax error:

 command = "commandToClient("srpcBuyIce"##)##;";
----------------------------------------------------------------------------------------------------------
Then I finally tried this last method, which doesn't involve the client.cs:

Gui:
Code: [Select]
new GuiBitmapButtonCtrl() {
         profile = "BlockButtonProfile";
         horizSizing = "relative";
         vertSizing = "relative";
         position = "12 81";
         extent = "100 39";
         minExtent = "8 2";
         enabled = "1";
         visible = "1";
         clipToParent = "1";
         command = "commandToServer("buyice", srpc_iceamt.getValue());";
         text = "Buy Ice Crystals";
         groupNum = "-1";
         buttonType = "PushButton";
         bitmap = "./button1";
         lockAspectRatio = "0";
         alignLeft = "0";
         overflowImage = "0";
         mKeepCached = "0";
         mColor = "0 255 255 255";
            wrap = "0";
      };
Syntax error:

command = "commandToServer("buyice", srpc_iceamt.getValue()##)##;";
-----------------------------------------------------------------------------------------------
Then, after being disappointed at this GUI, I did this (no client.cs):

Yes, there are 3 semicolons.

Gui:
Code: [Select]
new GuiBitmapButtonCtrl() {
         profile = "BlockButtonProfile";
         horizSizing = "relative";
         vertSizing = "relative";
         position = "12 81";
         extent = "100 39";
         minExtent = "8 2";
         enabled = "1";
         visible = "1";
         clipToParent = "1";
         command = "commandToServer("buyice", srpc_iceamt.getValue(););";
         text = "Buy Ice Crystals";
         groupNum = "-1";
         buttonType = "PushButton";
         bitmap = "./button1";
         lockAspectRatio = "0";
         alignLeft = "0";
         overflowImage = "0";
         mKeepCached = "0";
         mColor = "0 255 255 255";
            wrap = "0";
      };

Syntax error:

command = "commandToServer("buyice"##,## srpc_iceamt.getValue(););";
----------------------------------------------------------------------------------------------------------------------------------------------------
In summary, whenever I put a commandToClient or a CommandToServer inside, it has a syntax error.
Whenever I put a command that links to the client.cs inside, like srpcBuyIce();    ,  it crashes.
The GUI also hates commas that seperate arguments.

So how do I link the functions in the GUI to the server-sided script?[/code][/code]
« Last Edit: August 14, 2012, 10:25:35 AM by hammereditor² »

put \'s in the quotes inside the command quotes?

         command = "commandToServer(\"buyice\", srpc_iceamt.getValue(););";

         command = "commandToServer(\'buyice\', srpc_iceamt.getValue());";
I fixed it for Darren sillyman.

         command = "commandToServer(\"buyice\", srpc_iceamt.getValue(););";

ok thanx ill try that

Do Ipquarx's fix, I was on my phone at the time, didn't realise.

Oopsies.

Do Ipquarx's fix, I was on my phone at the time, didn't realise.

Oopsies.
Yes ill try that now...

I fixed it for Darren sillyman.
Thank you ipquarx!!It works!!!!


Would no-argument functions like this work: (by this, I mean no arguments on the client's side).
Code: [Select]
command = "commandToServer(\'help\');";


Just realised that you dont need backwards-slash when using ' ' s. it's only when you're using "s.

Just realised that you dont need backwards-slash when using ' ' s. it's only when you're using "s.
Well, it still works either way for me.