Jump to content

Recommended Posts

  • IIYAMA changed the title to [enhancement] MTA-Communication-Enhancement
  • 2 months later...

İts amazingly usefull!

I use this on my script but i have one question about multiple argument sending to server-side. Can you give a example for this?

callServer('isAccountRegistered', username,	function(state)
	if state then
		guiSetText(usernameEdt, '')
			return notifications:error(string.format('%s zaten kullanımda. Lütfen farklı bir ad seç.', username))
		end
	end
)

-- i wanna use multiple args when sending, for example.
callServer('isAccountRegistered', username, password, caseVariable, function(state)
 		-- TO DO
    end
)

 

  • Like 1
Link to comment
  • Moderators
On 06/02/2021 at 01:29, enesbayrktar said:

İts amazingly usefull!

thx!

Sorry for my late reply, I didn't notice the notification.


 

The syntax for that function:

bool callServer (callFunctionName string [, argument1, argument2, ... ] [, callbackFunction function [, argument1 (internal), argument2 (internal), ...]] )

https://gitlab.com/IIYAMA12/mta-communication-enchantment/tree/master/documentation/syntax#syntax-1

 

Multiple values can be send over by just adding them between the functionName and the callBackFunction.

functionName:

'isAccountRegistered'

callBackFunction:

function(state) end

 

callServer('isAccountRegistered', username, function(state) end) -- 1

callServer('isAccountRegistered', username, password, function(state) end) -- 2

callServer('isAccountRegistered', username, password, caseVariable, function(state) end) -- 3

It goes through all arguments and detects if there is a function, then that one will be the callBack function.

 

 

 


 

So you want to do that, what you already can do and doing it already?  ?

 

 

 

 

 

 

 

 

 

Edited by IIYAMA
  • Thanks 1
Link to comment
26 minutes ago, IIYAMA said:

thx!

Sorry for my late reply, I didn't notice the notification.


 

The syntax for that function:

bool callServer (callFunctionName string [, argument1, argument2, ... ] [, callbackFunction function [, argument1 (internal), argument2 (internal), ...]] )

https://gitlab.com/IIYAMA12/mta-communication-enchantment/tree/master/documentation/syntax#syntax-1

 

Multiple values can be send over by just adding them between the functionName and the callBackFunction.

functionName:


'isAccountRegistered'

callBackFunction:


function(state) end

 


callServer('isAccountRegistered', username, function(state) end) -- 1

callServer('isAccountRegistered', username, password, function(state) end) -- 2

callServer('isAccountRegistered', username, password, caseVariable, function(state) end) -- 3

It goes through all arguments and detects if there is a function, then that one will be the callBack function.

 

 

 


 

So you want to do that, what you already can do and doing it already?  ?

 

 

 

 

 

 

 

 

 

İ tested and its worked, but i dont know its true usage or not of multiple args for this reason i wanna a example code from you.

Thanks @IIYAMA

  • Like 1
Link to comment
  • Moderators
21 minutes ago, enesbayrktar said:

İ tested and its worked, but i dont know its true usage or not of multiple args for this reason i wanna a example code from you.

Thanks @IIYAMA

There is only 1 thing you need to know about internal arguments. Those ones that are after the callBack function.

If you mix internal arguments with arguments(from serverside), you have to make sure that the last internal argument is not a nil value.

 

Because when all arguments are converted to parameters, both lists will be merged and the first list(internal arguments) will collapse on nil values at the end of the table.

 

Problem:

internal2 = nil
callServer('isAccountRegistered', username, password, caseVariable, function(internal1, internal2, state) end, "internal1", internal2) 

 

Is OK:

internal2 = false
callServer('isAccountRegistered', username, password, caseVariable, function(internal1, internal2, state) end, "internal1", internal2) 

 

As you can see here:

list1 = {1, 2, nil, 4, nil} -- internal arguments
list2 = {6, 7, 8, 9, 10}

for i=1, #list2 do
  list1[#list1 + 1] = list2 [i]
end

print(unpack(list1))

-- 1,	2,	nil,	4,	6,	7,	8,	9,	10,
-- The nil value at index 5 is missing.

 

 

 

 

Edited by IIYAMA
Link to comment
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...