args of func

Schmeldric
Member
 
Posts: 19
Joined: Sat Nov 01, 2014 15:38
In-game: Schmeldric

args of func

by Schmeldric » Tue Nov 04, 2014 12:25

Hello,

I'm new to lua and to minetest, so I might be saying wrongs things.

I've had a look at the API, and at the register chat command page and tried out this example :
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.register_chatcommand("say", {
   params = "<text>",
   description = "Send text to chat",
   func = function(text)
      minetest.chat_send_all(text)
      return true, "Text was sent successfully"
   end,
})


When used, it prints "single player" on the chat. After looking a few mods, I tried this charge (parameters of the func) :
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.register_chatcommand("say", {
   params = "<text>",
   description = "Send text to chat",
   func = function(name, text)
      minetest.chat_send_all(text)
      return true, "Text was sent successfully"
   end,
})

Which seems more appropriate.

However, I'm a bit lost on he syntax. Are these assertions true?
- The string in "params" is useless for the computer -- it's just the /help message
- the function given to "func" will always have the same parameters : name, and a string with the end of the command line;
- if line above is correct, is this a generality for all "func" in every method, or is there a documentation somewhere?

By the way, if params contains multiple arguments (such as x y z) how should I parse the string to get them? (I haven't reach this page in my lua tutorial)

Thanks for reading
 

User avatar
srifqi
Member
 
Posts: 508
Joined: Sat Jun 28, 2014 04:31
GitHub: srifqi
IRC: srifqi
In-game: srifqi

Re: args of func

by srifqi » Tue Nov 04, 2014 14:07

Schmeldric wrote:Hello,

Hi,
Schmeldric wrote:I'm new to lua and to minetest, so I might be saying wrongs things.

It's okay. Many users have same problem when new to Minetest.
Schmeldric wrote:I've had a look at the API, and at the register chat command page and tried out this example :
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.register_chatcommand("say", {
   params = "<text>",
   description = "Send text to chat",
   func = function(text)
      minetest.chat_send_all(text)
      return true, "Text was sent successfully"
   end,
})


When used, it prints "single player" on the chat. After looking a few mods, I tried this charge (parameters of the func) :
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.register_chatcommand("say", {
   params = "<text>",
   description = "Send text to chat",
   func = function(name, text)
      minetest.chat_send_all(text)
      return true, "Text was sent successfully"
   end,
})

Which seems more appropriate.

It works!
Schmeldric wrote:However, I'm a bit lost on the syntax. Are these assertions true?
- The string in "params" is useless for the computer -- it's just the /help message
- the function given to "func" will always have the same parameters : name, and a string with the end of the command line;
- if line above is correct, is this a generality for all "func" in every method, or is there a documentation somewhere?

- But it's useful for player.
- True.
- Not it is not same for all method. I don't know any documentation. But maybe you can find it somewhere in Minetest Developer Wiki.
Schmeldric wrote:By the way, if params contains multiple arguments (such as x y z) how should I parse the string to get them? (I haven't reach this page in my lua tutorial)

You may use Regular Expression (RegExp). (Remeber: Lua doesn't use POSIX Regexp!)
Example:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
x, y, z = string.match(param, "^([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+)$")

See teleport chat command (/builtin/game/chatcommands.lua at line 261). It has advanced usage example for "x y z".
Schmeldric wrote:Thanks for reading

You're welcome!
I'm from Indonesia! Saya dari Indonesia!
Terjemahkan Minetest!
Mods by me. Modifikasi oleh saya.

Pronounce my nick as in: es-rifqi (IPA: /es rifˈki/)
 

Schmeldric
Member
 
Posts: 19
Joined: Sat Nov 01, 2014 15:38
In-game: Schmeldric

Re: args of func

by Schmeldric » Tue Nov 04, 2014 22:50

Oh! There are intersting stuff in this /builtin/game/ ! A lot to read/understand/copy/modify.

Thank you.
 


Return to Minetest Problems

Who is online

Users browsing this forum: No registered users and 23 guests

cron