First I considered just bumping the old thread, but it has a bit of confusing info at the beginning because the interface was still changing. So, new thread.
Important info for new LuaCOB users from that thread:
Handy wiki page, probably still all by imbaczek
The old thread
First off, I've been looking at how getting data back into the cob works: using get LUA0-9. What happens if you run multiple Lua scripts? And further, if you want data returned from them all? If I understand correctly, whichever function happens last would overwrite the values from the previous functions, at the very least, the one indicating if the call succeeded.
If that is the case, is it possible have a function's return skip over some of the values? Say, for one of them I only need to know it succeeded, but the next I need to know it succeeded and get 2 values returned. If I could have the second skip LUA0, and instead set my own confirmation in LUA1, then my values in LUA2-3, I wouldn't have to worry about both functions happening at once. I could even fit more in with LUA4-9. Though, I imagine having single units running too many LUA scripts is just a bad idea, I may not be able to get all the functionality I need working happily with just 1.
LUA <--> COB Revisited
Moderator: Moderators
-
- Posts: 854
- Joined: 28 Jan 2005, 18:15
-
- Posts: 854
- Joined: 28 Jan 2005, 18:15
Aye, I think KDR is starting to get what I'm saying. But I'm worried about a situation where Function2 starts before the script reaches x=LUA0. Such as (going to possible battletech related stuff) if I have one lua callout that occurs whenever a unit decides to use jumpjets, and another that occurs when the unit is low on ammo. The jumpjets are called from a fancy hitbyweapon extension (and maybe some terrain slope reader), and the ammo by the weapons themselves. I can't even begin to predict when one will be called, much less finished.
I suppose (on rereading) that LUA0 is set as soon as the function is called, not when it finishes, so there should only be a few milliseconds between when its called and an immediate check to see if it succeeded (and who would need anything less than immediate for that), and also since COB is (iirc) run line-by-line, that issue won't pop up at all. But that still leaves a question for all the others. Say, both functions also need a second return besides LUA0.
I suppose (on rereading) that LUA0 is set as soon as the function is called, not when it finishes, so there should only be a few milliseconds between when its called and an immediate check to see if it succeeded (and who would need anything less than immediate for that), and also since COB is (iirc) run line-by-line, that issue won't pop up at all. But that still leaves a question for all the others. Say, both functions also need a second return besides LUA0.
COB is cooperatively multitasked, only one function is executed at the same time. Otherwise you'd have to mark critical areas around every variable access.
Calling a lua function will pause the COB execution until the function is finished, after that COB execution resumes normally (like any other function call). Spring isn't really multithreaded so you don't have to worry about races in your script.
Calling a lua function will pause the COB execution until the function is finished, after that COB execution resumes normally (like any other function call). Spring isn't really multithreaded so you don't have to worry about races in your script.
-
- Posts: 854
- Joined: 28 Jan 2005, 18:15
-
- Posts: 854
- Joined: 28 Jan 2005, 18:15
New question! Ahh, the search function.
Back in this thread trepan mentioned:
Back in this thread trepan mentioned:
So, this calling cob functions, can I do it from LuaCob? From LuaRules? As an aside, how would the speed of sending data back through calling a cob function and passing parameters compare to use get LUA0-9?trepan wrote:For all you BOS scripters...
...other cool stuff... Combined with the ability to call cob functions directly
from the game console(via the lua interface) ...