Ok thanks alot! This helps alot! Do the files need to have a special extension for the -r parameter to work?
Nope, any name should be fine
Can I just put all the commands into the file like this?
!mc=require('multicam')
!mc:connect()
!mc:start()
!return mc:cmdwait('rec')
!return mc:cmdwait('preshoot')
!return mc:cmdwait('shoot')
!return mc:cmdwait('play')
!mc:cmd('exit')
Yes, doing it that way should be fine (in principle, I haven't checked that all those commands are correct)
All that is local Lua code, so you could also put the calls in a lua file (without the !), and execute it with something like -e"exec dofile('myfile.lua')"
("exec" is the same as !, but some unix-ish shells might do funny things to it, so "exec" is safer on the command line). You'd need to remove or replace the "return" statements.
This would give you give you more flexibility if you need any actual logic in your script, or want to display the return output in a more user friendly manner. If the quoted code is all you need, then a chdkptp -r file should be fine.
I want to get 8 cameras taking pictures at the same time (Within about 500 milliseconds). Entering the commands manually (First running chdkptp -i) works just fine...
Note that the way you are doing things now, each camera will just execute the shoot command as soon as it arrives. multicam sends the commands sequentially, so there will be a gap between the first and last. If you want better sync, you should use init_sync and then shoot with a sync time, like
!mc:cmdwait('shoot',{syncat=100})
Off the top of my head, I'd expect you can get 8 cameras within 500ms without using init_sync. The "minimum sync delay" will give you an approximation of the amount of time it takes to send to all cameras.
Another note:
You may find you need some delay between things like rec and preshoot or shoot and play. You can insert a delay on the chdkptp side using sys.sleep(milliseconds)