[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
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.)
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:
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
function srpcBuyIce(%gui)
{
%amt = srpc_creditamt.getValue();
commandToServer("buyice", %amt);
}
Gui
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:
function clientCmdsrpcBuyIce(%gui)
{
%amt = srpc_creditamt.getValue();
commandToServer("buyice", %amt);
}
Gui:
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:
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:
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]