Matrix Games Forums

Forums  Register  Login  Photo Gallery  Member List  Search  Calendars  FAQ 

My Profile  Inbox  Address Book  My Subscription  My Forums  Log Out

Question about LUA ScenEdit_SetUnit

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
  Printable Version
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Question about LUA ScenEdit_SetUnit Page: [1]
Login
Message << Older Topic   Newer Topic >>
Question about LUA ScenEdit_SetUnit - 3/28/2016 3:00:58 AM   
Gizzmoe


Posts: 155
Joined: 8/24/2005
From: Germany
Status: offline
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!
Post #: 1
RE: Question about LUA ScenEdit_SetUnit - 3/28/2016 12:01:12 PM   
michaelm75au


Posts: 13500
Joined: 5/5/2001
From: Melbourne, Australia
Status: offline
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

< Message edited by michaelm -- 3/28/2016 12:08:57 PM >


_____________________________

Michael

(in reply to Gizzmoe)
Post #: 2
RE: Question about LUA ScenEdit_SetUnit - 3/28/2016 12:23:08 PM   
DeSade

 

Posts: 156
Joined: 3/1/2004
Status: offline
If you place new plane at proper altitude then AddUnit works fine:

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

with altitude param set.

(in reply to Gizzmoe)
Post #: 3
RE: Question about LUA ScenEdit_SetUnit - 3/28/2016 12:24:53 PM   
Gizzmoe


Posts: 155
Joined: 8/24/2005
From: Germany
Status: offline

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!!!

< Message edited by Gizzmoe -- 3/28/2016 12:26:06 PM >

(in reply to michaelm75au)
Post #: 4
RE: Question about LUA ScenEdit_SetUnit - 3/28/2016 12:52:36 PM   
Gizzmoe


Posts: 155
Joined: 8/24/2005
From: Germany
Status: offline
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...

< Message edited by Gizzmoe -- 3/28/2016 12:56:24 PM >

(in reply to Gizzmoe)
Post #: 5
RE: Question about LUA ScenEdit_SetUnit - 3/29/2016 2:21:03 PM   
ckfinite

 

Posts: 377
Joined: 7/20/2013
Status: offline
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

(in reply to Gizzmoe)
Post #: 6
RE: Question about LUA ScenEdit_SetUnit - 3/29/2016 4:23:51 PM   
Gizzmoe


Posts: 155
Joined: 8/24/2005
From: Germany
Status: offline
^ Thanks for your help and the link! :)

(in reply to ckfinite)
Post #: 7
RE: Question about LUA ScenEdit_SetUnit - 3/29/2016 8:14:44 PM   
Gizzmoe


Posts: 155
Joined: 8/24/2005
From: Germany
Status: offline

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

(in reply to ckfinite)
Post #: 8
RE: Question about LUA ScenEdit_SetUnit - 3/29/2016 8:18:23 PM   
thewood1

 

Posts: 6529
Joined: 11/27/2005
Status: offline
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.

(in reply to Gizzmoe)
Post #: 9
RE: Question about LUA ScenEdit_SetUnit - 3/29/2016 8:31:04 PM   
zaytsev

 

Posts: 99
Joined: 6/16/2014
Status: offline
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


< Message edited by zaytsev -- 3/29/2016 8:32:43 PM >

(in reply to Gizzmoe)
Post #: 10
RE: Question about LUA ScenEdit_SetUnit - 3/29/2016 8:40:27 PM   
Gizzmoe


Posts: 155
Joined: 8/24/2005
From: Germany
Status: offline

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 :)


(in reply to thewood1)
Post #: 11
RE: Question about LUA ScenEdit_SetUnit - 3/29/2016 8:42:31 PM   
thewood1

 

Posts: 6529
Joined: 11/27/2005
Status: offline
OK, so I'm sure posting here constantly will solve the problem.

(in reply to Gizzmoe)
Post #: 12
RE: Question about LUA ScenEdit_SetUnit - 3/29/2016 8:51:46 PM   
Gizzmoe


Posts: 155
Joined: 8/24/2005
From: Germany
Status: offline
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!!! ;)

(in reply to thewood1)
Post #: 13
RE: Question about LUA ScenEdit_SetUnit - 3/29/2016 9:07:42 PM   
thewood1

 

Posts: 6529
Joined: 11/27/2005
Status: offline
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.

(in reply to Gizzmoe)
Post #: 14
RE: Question about LUA ScenEdit_SetUnit - 3/29/2016 9:17:16 PM   
mikmykWS

 

Posts: 11524
Joined: 3/22/2005
Status: offline
Question and Answer site is actually best for this

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

Mike

_____________________________


(in reply to thewood1)
Post #: 15
RE: Question about LUA ScenEdit_SetUnit - 3/29/2016 9:24:33 PM   
Gizzmoe


Posts: 155
Joined: 8/24/2005
From: Germany
Status: offline

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.

(in reply to mikmykWS)
Post #: 16
RE: Question about LUA ScenEdit_SetUnit - 3/29/2016 10:27:58 PM   
thewood1

 

Posts: 6529
Joined: 11/27/2005
Status: offline
...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.

(in reply to Gizzmoe)
Post #: 17
RE: Question about LUA ScenEdit_SetUnit - 3/30/2016 2:05:58 AM   
ckfinite

 

Posts: 377
Joined: 7/20/2013
Status: offline
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

< Message edited by ckfinite -- 3/30/2016 2:06:46 AM >

(in reply to thewood1)
Post #: 18
RE: Question about LUA ScenEdit_SetUnit - 3/30/2016 11:09:50 AM   
zaytsev

 

Posts: 99
Joined: 6/16/2014
Status: offline
darn , you've beat me to it

found it , crude (my 1st steps in lua) , but somehow working
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)
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

< Message edited by zaytsev -- 3/30/2016 11:24:54 AM >

(in reply to ckfinite)
Post #: 19
RE: Question about LUA ScenEdit_SetUnit - 3/30/2016 5:20:03 PM   
Gizzmoe


Posts: 155
Joined: 8/24/2005
From: Germany
Status: offline
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 :)

(in reply to Gizzmoe)
Post #: 20
Page:   [1]
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Question about LUA ScenEdit_SetUnit Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts


Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI

2.344