Mathematic function on LuaScript

Typically: "How do I... ", "How can I... " questions
aven
Posts: 8
Joined: 27 Feb 2020, 11:35

Mathematic function on LuaScript

Good morning,
I would like to create a math function (e.g. a sawtooth) in a LuaScript in order to plot it in another program. Is there a way to fix it? I read the section 6.6 at the manual,http://www.lua.org/manual/5.2/manual.html#6.6, but I did not find the solution.

Thank you

fferri
Posts: 556
Joined: 09 Sep 2013, 19:28

Re: Mathematic function on LuaScript

Not sure I understand what you are looking for.

Code: Select all

> function math.saw(x) return math.fmod(x,1) end
> for x=0,3,0.2 do print(x..'\t'..math.saw(x)) end
0	0
0.2	0.2
0.4	0.4
0.6	0.6
0.8	0.8
1	0
1.2	0.2
1.4	0.4
1.6	0.6
1.8	0.8
2	1
2.2	0.2
2.4	0.4
2.6	0.6
2.8	0.8

aven
Posts: 8
Joined: 27 Feb 2020, 11:35

Re: Mathematic function on LuaScript

fferri wrote:
25 Mar 2020, 12:20
Not sure I understand what you are looking for.

Code: Select all

> function math.saw(x) return math.fmod(x,1) end
> for x=0,3,0.2 do print(x..'\t'..math.saw(x)) end
0	0
0.2	0.2
0.4	0.4
0.6	0.6
0.8	0.8
1	0
1.2	0.2
1.4	0.4
1.6	0.6
1.8	0.8
2	1
2.2	0.2
2.4	0.4
2.6	0.6
2.8	0.8
Yes, it seems something like I need. Where may I find info about

Code: Select all

math.saw()
and

Code: Select all

math.fmod()
?

fferri
Posts: 556
Joined: 09 Sep 2013, 19:28

Re: Mathematic function on LuaScript

math.saw is the function I just defined.

math.modf is described in the link you posted earlier.

CoppeliaSim manual has a Lua crash course, and there are more learning resources on the Lua website.

aven
Posts: 8
Joined: 27 Feb 2020, 11:35

Re: Mathematic function on LuaScript

fferri wrote:
25 Mar 2020, 12:59
math.saw is the function I just defined.

math.modf is described in the link you posted earlier.

CoppeliaSim manual has a Lua crash course, and there are more learning resources on the Lua website.
You're right, thank you. It works fine.