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

## Mathematic function on LuaScript

### Re: Mathematic function on LuaScript

Not sure I understand what you are looking for.

How about this:

How about this:

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
```

### Re: Mathematic function on LuaScript

Yes, it seems something like I need. Where may I find info aboutfferri wrote: ↑25 Mar 2020, 12:20Not sure I understand what you are looking for.

How about this:

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`

Code: Select all

`math.saw()`

Code: Select all

`math.fmod()`

### 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.

### Re: Mathematic function on LuaScript

You're right, thank you. It works fine.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.