This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
macss_'s profile picture

Functions

Started by macss_, 18 May 2014 - 07:04 PM
macss_ #1
Posted 18 May 2014 - 09:04 PM
Is it possible to stabilish "global" functions that I can call in in any program?

like

function rednetSend(msg)
msg = tostring(msg)
redenet.broadcast(msg)
end

So i can call it in any program i have.
CometWolf #2
Posted 18 May 2014 - 09:06 PM
You just did, any non local variable is acessible from all programs after it has been defined until the computer reboots.
Lignum #3
Posted 18 May 2014 - 09:07 PM
No, not really. But you can make an API.
EDIT: Never mind, just tried it, CometWolf is right. Lua never ceases to amaze me with its magic.
Edited on 18 May 2014 - 07:08 PM
macss_ #4
Posted 18 May 2014 - 09:07 PM
So if I run a program called "function" then terminate it an imediatly after i execute rednetSend("Hello") the message will be sent?
Lignum #5
Posted 18 May 2014 - 09:09 PM
So if I run a program called "function" then terminate it an imediatly after i execute rednetSend("Hello") the message will be sent?
Yes.
macss_ #6
Posted 18 May 2014 - 09:14 PM
Well, thank you so! :D/>