Advertisement
Guest User

Untitled

a guest
Jun 13th, 2015
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. 3 additional commands which are sent only by server:
  2. 1. execute script directly
  3. 2. bind function to id
  4. 3. execute function bound to id (with optional payload)
  5.  
  6. Scripts are sent to client as bytecode.
  7.  
  8. about 2 and 3:
  9. - It's worth noting that no ID is needed at all.
  10. We can just bind some general callback for later execution and this
  11. callback could read specific part of payload and by that know which
  12. command to run. However, Lua does not have switch statement and execution
  13. of lot of "if" statements just to know which command to run is not optimal,
  14. so maybe having function ID is not bad at all.
  15. - Binding a function without arguments to some ID is bit useless, isn't it?
  16. We want to pass some arguments to bound functions and this can be
  17. accomplished by having some payload after function ID.
  18.  
  19. How I see it in scripting:
  20.  
  21. minetest.register_on_clientside_call(id, callback)
  22. callback is a function or string
  23. string is sent as is, but callback is converted to bytecode (also a string)
  24. actually string.dump(f) converts a function f to bytecode
  25.  
  26. example:
  27.  
  28. -- direct
  29. minetest.clientside_execute(function()
  30. local player = minetest.get_current_player()
  31. minetest.chat_send_player(player:get_name(), "Hello")
  32. end)
  33.  
  34. -- indirect
  35. minetest.clientside_bind(10, function(payload)
  36. local player = minetest.get_current_player()
  37. minetest.chat_send_player(player:get_name(), payload)
  38. end)
  39.  
  40. minetest.clientside_call(10, "Hello")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement