Question about LUA ScenEdit_SetUnit (Full Version)

All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series



Message


Gizzmoe -> Question about LUA ScenEdit_SetUnit (3/28/2016 3:00:58 AM)

Hi! As there seems to be no direct way to set the initial altitude of a newly placed aircraft in the scenario editor I tried to set it with the ScenEdit_SetUnit (made an event that triggered it at mission start), but it doesn't work. If it can be done with ScenEdit_SetUnit, what's the right syntax? Thanks!




michaelm75au -> RE: Question about LUA ScenEdit_SetUnit (3/28/2016 12:01:12 PM)

Something like this as I don't know details of what you trying:
unit = ScenEdit_GetUnit({side="A", name="Bomber#1"});
print( unit.altitude); # before
unit.altitude = 5000;  # altitude in metres
print( unit.altitude); # after


I find GetUnit() is better as you can check that it got a non-NULL unit object back




DeSade -> RE: Question about LUA ScenEdit_SetUnit (3/28/2016 12:23:08 PM)

If you place new plane at proper altitude then AddUnit works fine:

http://commandlua.github.io/#ScenEdit_AddUnit

with altitude param set.




Gizzmoe -> RE: Question about LUA ScenEdit_SetUnit (3/28/2016 12:24:53 PM)


quote:

ORIGINAL: michaelm

Something like this as I don't know details of what you trying:
unit = ScenEdit_GetUnit({side="A", name="Bomber#1"});
print( unit.altitude); # before
unit.altitude = 5000;  # altitude in metres
print( unit.altitude); # after


OMG, that worked, thanks a lot!!! [&o]




Gizzmoe -> RE: Question about LUA ScenEdit_SetUnit (3/28/2016 12:52:36 PM)

By the way, does lua support arrays? Or is there any other direct way to change altitude/speed for an entire group?

I know I could use AddUnit, but that looks like a very annoying way, having to look for loadout IDs, Lat/Lon and stuff...




ckfinite -> RE: Question about LUA ScenEdit_SetUnit (3/29/2016 2:21:03 PM)

quote:

By the way, does lua support arrays? Or is there any other direct way to change altitude/speed for an entire group?


Lua supports arrays and loops, see here. There currently isn't a good way to introspect into groups, so your only real option is to leverage common naming conventions.

For example, you could write

for i=1,12 do
ScenEdit_GetUnit({side="A", name="Black Adder #".. i}).altitude = 5000
end




Gizzmoe -> RE: Question about LUA ScenEdit_SetUnit (3/29/2016 4:23:51 PM)

^ Thanks for your help and the link! :)




Gizzmoe -> RE: Question about LUA ScenEdit_SetUnit (3/29/2016 8:14:44 PM)


quote:

ORIGINAL: ckfinite

for i=1,12 do
ScenEdit_GetUnit({side="A", name="Black Adder #".. i}).altitude = 5000
end


I get an error message running this:
ERROR: [string "chunk"]:2: attempt to index a nil value

I placed three aircraft, side Blue, named them Flight 1 to 3 and used this code:
for i=1,3 do
ScenEdit_GetUnit({side="Blue", name="Flight #".. i}).altitude = 5000
end




thewood1 -> RE: Question about LUA ScenEdit_SetUnit (3/29/2016 8:18:23 PM)

Can I suggest you visit some of the lua boards. Some of these questions are general lua questions. You need at least a basic foundation. Those boards can be searched easily and you'll probably get faster answers.




zaytsev -> RE: Question about LUA ScenEdit_SetUnit (3/29/2016 8:31:04 PM)

quote:

ORIGINAL: Gizzmoe
quote:

ORIGINAL: ckfinite
for i=1,12 do
ScenEdit_GetUnit({side="A", name="Black Adder #".. i}).altitude = 5000
end

I get an error message running this:
ERROR: [string "chunk"]:2: attempt to index a nil value
I placed three aircraft, side Blue, named them Flight 1 to 3 and used this code:
for i=1,3 do
ScenEdit_GetUnit({side="Blue", name="Flight #".. i}).altitude = 5000
end


mmm , unfortunately i don't have results yet , but i'm in same trouble myself
i've tried few things but no luck

this works
u = ScenEdit_GetUnit({name="Eyeball" .. " #2"})
print (u)


but this dont
u = ScenEdit_GetUnit({name="Eyeball" .. "???"})
u = ScenEdit_GetUnit({name="Eyeball" .. ".*"})
u = ScenEdit_GetUnit({name="Eyeball" .. "..."})
u = ScenEdit_GetUnit({name="Eyeball" .. "..%d"})
etc...


your best bet is to look for lua table concatenation and/or regular exp.

i'm doing it currently, will post if sumtin' cums up...

Cheers




Gizzmoe -> RE: Question about LUA ScenEdit_SetUnit (3/29/2016 8:40:27 PM)


quote:

ORIGINAL: thewood1
Can I suggest you visit some of the lua boards. Some of these questions are general lua questions. You need at least a basic foundation. Those boards can be searched easily and you'll probably get faster answers.


Thanks, but I'm fine at the moment, this altitude thing is the only thing so far I want to see running with lua and I don't want to spend quite a while to build up a basic foundation for just that one use. I get there later maybe :)





thewood1 -> RE: Question about LUA ScenEdit_SetUnit (3/29/2016 8:42:31 PM)

OK, so I'm sure posting here constantly will solve the problem.




Gizzmoe -> RE: Question about LUA ScenEdit_SetUnit (3/29/2016 8:51:46 PM)

quote:

ORIGINAL: thewood1
OK, so I'm sure posting here constantly will solve the problem.


Excuse me for asking questions in an internet forum, in my own thread!!! ;)




thewood1 -> RE: Question about LUA ScenEdit_SetUnit (3/29/2016 9:07:42 PM)

You're excused...its just that constantly posting waiting for someone to solve your problem when you can take a few minutes and do a google search and answer the question. Its your time, but you seem to like wasting it.




mikmykWS -> RE: Question about LUA ScenEdit_SetUnit (3/29/2016 9:17:16 PM)

Question and Answer site is actually best for this

http://www.matrixgames.com/forums/tm.asp?m=4000678

Mike




Gizzmoe -> RE: Question about LUA ScenEdit_SetUnit (3/29/2016 9:24:33 PM)


quote:

ORIGINAL: mikmyk

Question and Answer site is actually best for this

http://www.matrixgames.com/forums/tm.asp?m=4000678

Mike


Nice, didn't know the Q&A site yet.




thewood1 -> RE: Question about LUA ScenEdit_SetUnit (3/29/2016 10:27:58 PM)

...and that is exactly my point. There are a bunch of resources listed in the sticky section that anyone playing the game should use.

I suggest taking a breath, starting out simple, and reading everything that is posted up there. Someone new to the game jumping into Lua immediately is going to lead to frustration all around.




ckfinite -> RE: Question about LUA ScenEdit_SetUnit (3/30/2016 2:05:58 AM)

quote:

I get an error message running this:
ERROR: [string "chunk"]:2: attempt to index a nil value


Yes, that was just an example. Your adaptation of the example was correct for the scene you made.

quote:

u = ScenEdit_GetUnit({name="Eyeball" .. " #2"})
print (u)


What you need to do is (where 12 is the number of units that are in this sequence of names)

for i=1,12 do
u = ScenEdit_GetUnit({name="Eyeball #"..i, side="[YOUR SIDE HERE]"})
print(u)
end




zaytsev -> RE: Question about LUA ScenEdit_SetUnit (3/30/2016 11:09:50 AM)

darn , you've beat me to it [8D]

found it , crude (my 1st steps in lua) , but somehow working [:D]
but, Thanks

for a = 1,3 do
u = ScenEdit_GetUnit({name="Eyeball" .. (" #"..a)})
print (u)
end


still cant get regexp working .. need more try'n'error i guess
constantly i get errors for missinterpreting '%' as arithmetic (modulo)
instead escape character for regexp like '%d'=digits

no big deal, jut wanted to see it working (i like regexp[:D])
it is too powerfull

still can use normal strings and variables tho


- what i'm really trying to reproduce is fetch many unique names , not incremental counters.
eg. to find units with duplicate names, one or many with the 'same name' string
currently it fetches only one, first result, but if there are more of the same name, would need to build
something as incremental list, or something ...
would use 'side' only to truncate list even more
...still learning, tho

Cheers




Gizzmoe -> RE: Question about LUA ScenEdit_SetUnit (3/30/2016 5:20:03 PM)

quote:

ORIGINAL: Gizzmoe
I get an error message running this:
ERROR: [string "chunk"]:2: attempt to index a nil value

I placed three aircraft, side Blue, named them Flight 1 to 3 and used this code:
for i=1,3 do
ScenEdit_GetUnit({side="Blue", name="Flight #".. i}).altitude = 5000
end


Duuuh, all I had to do to make this work is to remove the #. I am happy now :)




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.671875