Jump to content

Help with LUA / MIST


OneFatBird

Recommended Posts

I don't know. This language defeats me again and again. It looks like a hybrid of BASIC and C, but behaves like neither.

 

From my days of C++, you could evaluate an "if" TRUE or FALSE statement implicitly by an expression, roughly like this, for example...

 

if (apc.getByName(_grp)) 

// if it got something, it was true, otherwise false.

I'm trying to do that, but nothing works. Here...

 

_apc_names = {"APC_U_1", "APC_U_2", "APC_U_3", "APC_U_4", "APC_U_5", "APC_U_6", "APC_U_7", "APC_U_8", }

-- These are units I have made in the ME. Some might already be dead during runtime. I want dead ones to evaluate false, live ones true.

for _i, _gp in pairs(_apc_names) do

   if _apc = Unit.getByName(_gp) then
   --  if (_apc = Unit.getByName(_gp)) then
   
   _apcPos = _apc:getPosition().p

  -- etcetera

end

No matter what I do, it throws errors at that evaluation of the expression point.

 

How's it done, please?

Link to comment
Share on other sites

I don't know. This language defeats me again and again. It looks like a hybrid of BASIC and C, but behaves like neither.

 

From my days of C++, you could evaluate an "if" TRUE or FALSE statement implicitly by an expression, roughly like this, for example...

 

if (apc.getByName(_grp)) 

// if it got something, it was true, otherwise false.

I'm trying to do that, but nothing works. Here...

 

_apc_names = {"APC_U_1", "APC_U_2", "APC_U_3", "APC_U_4", "APC_U_5", "APC_U_6", "APC_U_7", "APC_U_8", }

-- These are units I have made in the ME. Some might already be dead during runtime. I want dead ones to evaluate false, live ones true.

for _i, _gp in pairs(_apc_names) do

   if _apc = Unit.getByName(_gp) then
   --  if (_apc = Unit.getByName(_gp)) then
   
   _apcPos = _apc:getPosition().p

  -- etcetera

end

No matter what I do, it throws errors at that evaluation of the expression point.

 

How's it done, please?

 

Not to be *that* guy, but honestly, if you take just a couple of hours to skim (not even read) the language reference (just the first two chapters of: https://www.lua.org/manual/5.3/), you are going to save yourself hours of frustration. It's false economics to think you are saving time by not doing this, and you are really doing yourself a disservice as well as this community. If someone said that knew some Lua and then wanted to try programming in C++ without doing due diligence in trying the learn the language, what would you say to them?

 

Sorry if end up offending you with the above.

 

If you have skimmed the language reference, then also sorry for assuming that you did not.

 

Anyway, in answer to your problem ...

 

"=" is assignment.

 

"==" is testing for equality.

Link to comment
Share on other sites

Anyway, in answer to your problem ...

 

"=" is assignment.

 

"==" is testing for equality.

 

Yes, I do know that. It is the same in C.

 

Sorry you're not understanding what I am really asking. And yes, I am constantly referring to the Lua, MiST and DCS Scripting Documentation (the last of these which is very, very hard to digest, I will add).

 

In any case, I do not learn as well as I used to because I'm old now. Apologies for that too, sir, though there's not much I can do about it. I won't bug you anymore. I was just doing it as a hobby, but I can clearly see I'm irking you all.

 

Respects. All the best!

Link to comment
Share on other sites

Yes, I do know that. It is the same in C.

 

Sorry you're not understanding what I am really asking. And yes, I am constantly referring to the Lua, MiST and DCS Scripting Documentation (the last of these which is very, very hard to digest, I will add).

 

In any case, I do not learn as well as I used to because I'm old now. Apologies for that too, sir, though there's not much I can do about it. I won't bug you anymore. I was just doing it as a hobby, but I can clearly see I'm irking you all.

 

Respects. All the best!

 

In your example, you are using the assignment operator instead of the equality operator in your conditionals:

 

for _i, _gp in pairs(_apc_names) do

   if _apc = Unit.getByName(_gp) then

 

 

That is at least one problem.

 

As for documentation, yes, the DCS scripting engine documentation is not overwhelmingly thorough or up-to-date. A lot is there, but a lot is not. For that, the solution is to, indeed, ask the community. But I suspect your issue here is a basic Lua problem and not a DCS engine problem.

 

As for age, hey, we are all getting old. And the only way to help our old minds keep learning is keep on learning!

 

Please continue your efforts and questions, even if the responses come sometimes grumpy (the other side-effect of growing old? At least, on my part).

Link to comment
Share on other sites

In your example, you are using the assignment operator instead of the equality operator in your conditionals:

 

for _i, _gp in pairs(_apc_names) do

   if _apc = Unit.getByName(_gp) then

That is at least one problem.

 

I must clarify, first, what is wrong with my reasoning, and I recognize it is wrong. I'm trying to force a new language (for me) to do things that I am familiar with from another language. I should know better, having been a reasonably talented C/C++ coder on the verge of a decade ago. Here's a link to what I was referring to. See how you can use either the equality or the assignment operators for true false evaluation? The advantage was, if it proved true, it also retained the value obtained from the operation (or API procedure, whatever the case was) for use in the rest of the if statement.

 

Lua does not do it, it seems, so I find a walk around, and that turns out to be the correct way for Lua. By that I mean, yes, I have solved my issue. Here's a snippet;

 

_apc_names = {"APC_U_1", "APC_U_2", "APC_U_3" ...and so on... }

for _i, _gp in pairs(_apc_names) do

   _apc = Unit.getByName(_gp)
   
   if _apc ~= nil then
       _apcPos = _apc:getPosition().p
       
      -- handling code, and such...
   end
end

Works great now.

 

As for documentation, yes, the DCS scripting engine documentation is not overwhelmingly thorough or up-to-date. A lot is there, but a lot is not. For that, the solution is to, indeed, ask the community. But I suspect your issue here is a basic Lua problem and not a DCS engine problem.
Yeah, well. Symptom of the times. We can't even buy a phone now with a half decent instruction manual included, as it appears modern human kind learns by osmosis, or something, LOL! Just have to get used to that. :P

 

As for age, hey, we are all getting old. And the only way to help our old minds keep learning is keep on learning!
These are true words of wisdom. Thanks.

 

Again, sorry I'm slow nowadays.

  • Like 1
Link to comment
Share on other sites

I am old, i have never ever programmed. Anything, and i am starting to do some little stuff. I have read the manual, few times, and I am doing it again a again. Each time, a learn something new. But i have to ask for the simpliest thing... I like to think that there is not wrong with that. Sometimes you are answerd, others you dont. But, please, do not tell us off if we dont have your skills.it is not very kind.

Link to comment
Share on other sites

I am old, i have never ever programmed. Anything, and i am starting to do some little stuff. I have read the manual, few times, and I am doing it again a again. Each time, a learn something new. But i have to ask for the simpliest thing... I like to think that there is not wrong with that. Sometimes you are answerd, others you dont. But, please, do not tell us off if we dont have your skills.it is not very kind.

 

Please do not make this what is not. Nobody is telling anyone off for not having skills. The OP was unfamiliar with Lua, and was assuming that knowledge of C++ was sufficient to brute force his way through Lua. I pointed out that it would save him a lot of frustration if he took at least the minimum effort tried to familiarize himself with basic Lua instead of assuming that the syntax was the same.

 

This is the truth.

 

It is painful, maybe.

 

But it is the truth.

 

I was NOT criticizing the OP for having insufficient skills.

 

I was NOT criticizing the OP for asking questions.

 

I WAS saying that assuming that Lua was the same as C++ instead of reading up on Lua basics was a recipe for frustration.

 

I WAS suggesting that the OP reading up on Lua to save himself a lot of time and let his questions focus on the more complicated stuff, such as the DCS engines, rather than the basics of Lua syntax which can be found in any book.

 

Also note that both the OP and myself were polite and civil, AND I provided links to the Lua materials ... AND, most importantly, I answered the OP's questions multiple times in this thread!

 

None of that has been acknowledged in your rush to condemn.

 

So, please do not suggest that I was being mean and rude for a perceived slight that not only had nothing to do with you, but also is a complete mischaracterization of what took place. I have been helpful in these forums in the past. Interactions like this are certainly discouraging enough to make me reconsider.

Link to comment
Share on other sites

Ok!!! Dont worry. I get your point. It sounded a bit tough post to me. My fault ;)

 

If you are bored.... Have a look at some of my enquires about Lua hhjjjaa

 

No problems! I am no expert, either, actually, and just learning as well. We can help each other.

Link to comment
Share on other sites

Huh! What happens while a back is turned, LOL! I'm sorry that I - or the content of the thread - was misinterpreted. Makes me feel guilty for starting a contratom.

 

Indeed, questions have been answered to a level of satisfaction; my thanks for that.

 

No problems! I am no expert, either, actually, and just learning as well. We can help each other.

 

Known to be the best way to expand your knowledge; start teaching as soon as you have a functional grasp on a subject, provided you have the benefit of time to research and then reply. I know that from experience in another field.

 

In any case, I am now well away with beginning to write my own scripts; the "click" has finally manifested itself, alas. I'll just bother you generous people - to whom I'm grateful - when I get really, really, REALLY stuck with something, as from now.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...