Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 3 additional commands which are sent only by server:
- 1. execute script directly
- 2. bind function to id
- 3. execute function bound to id (with optional payload)
- Scripts are sent to client as bytecode.
- about 2 and 3:
- - It's worth noting that no ID is needed at all.
- We can just bind some general callback for later execution and this
- callback could read specific part of payload and by that know which
- command to run. However, Lua does not have switch statement and execution
- of lot of "if" statements just to know which command to run is not optimal,
- so maybe having function ID is not bad at all.
- - Binding a function without arguments to some ID is bit useless, isn't it?
- We want to pass some arguments to bound functions and this can be
- accomplished by having some payload after function ID.
- How I see it in scripting:
- minetest.register_on_clientside_call(id, callback)
- callback is a function or string
- string is sent as is, but callback is converted to bytecode (also a string)
- actually string.dump(f) converts a function f to bytecode
- example:
- -- direct
- minetest.clientside_execute(function()
- local player = minetest.get_current_player()
- minetest.chat_send_player(player:get_name(), "Hello")
- end)
- -- indirect
- minetest.clientside_bind(10, function(payload)
- local player = minetest.get_current_player()
- minetest.chat_send_player(player:get_name(), payload)
- end)
- minetest.clientside_call(10, "Hello")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement