Function definition in child script

Typically: "How do I... ", "How can I... " questions
Post Reply
horothesun
Posts: 3
Joined: 13 Jan 2015, 11:10

Function definition in child script

Post by horothesun »

Hi all! I'm new to this amazing simulator and i have a pretty newbie question to ask:

how can i define (then call) my own Lua functions in a child script?

"-- DO NOT WRITE CODE OUTSIDE OF THE if-then-end SECTIONS BELOW!!" blocked me :(

TIA,
Nicola.

coppelia
Site Admin
Posts: 10381
Joined: 14 Dec 2012, 00:25

Re: Function definition in child script

Post by coppelia »

Hello Nicola,

actually you can write code outside of the mentioned section, as long as the code represents a function.

So following is a valid child script:

Code: Select all

myFunction=function(a,b)
	return a+b
end

if (sim_call_type==sim_childscriptcall_initialization) then

end


if (sim_call_type==sim_childscriptcall_actuation) then
	print(myFunction(1,2))
end


if (sim_call_type==sim_childscriptcall_sensing) then

end


if (sim_call_type==sim_childscriptcall_cleanup) then

end
Cheers

horothesun
Posts: 3
Joined: 13 Jan 2015, 11:10

Re: Function definition in child script

Post by horothesun »

Thanks! ;)

Post Reply