Page 1 of 1

[LUA] Two doubts

Posted: Wed Apr 13, 2011 6:14 pm
by Sensoker
OK, so i think i understand everything except the use of Multithreading. I can't understand how or when to use it, nor the meaning of YieldTask (sorry, i'm not a native english speaker :oops: ). Could someone explain that?

The second question is simple: has someone developed any function in order to know if a particular radar has detected an enemy unit, or if a air unit has any enemy unit within its range? Or any ideas on how to implement this?

Thank you!

Posted: Wed Apr 13, 2011 11:04 pm
by trickser
YieldTask() inside a StartLongTask() block will stop execution of this code block for this GameTick and resume next GameTick.

For the questions if an unit has been detected simple compare the table GetAllUnits () returns in current tick with a table you got in last tick.
There is a hint about using the time field in GetAllUnitData() in the LuaBot documentation to track visible units.

Posted: Mon Apr 18, 2011 10:02 pm
by Sensoker
Thanks!

Another question. Inside the OnEvent function, which would mean the targetID, sourceID and object type?

Posted: Mon Apr 18, 2011 10:25 pm
by Ace Rimmer
I can't remember the difference betweeen sourceID and targetID, but you can look here for more information if you haven't already:

http://www.corsix.org/defcon_luabot/doc ... fn-OnEvent

Posted: Mon Apr 18, 2011 10:49 pm
by Sensoker
Ace Rimmer wrote:I can't remember the difference betweeen sourceID and targetID, but you can look here for more information if you haven't already:

http://www.corsix.org/defcon_luabot/doc ... fn-OnEvent


I tried, and i assumed that, e.g. in a Hit event, the sourceID would be the firing unit, and the targetID the unit hit, but i'm getting some contradictions on that. Besides, i don't know how to deal with unit type. What unit is it, the source, the target..?

Posted: Tue Apr 19, 2011 5:52 pm
by trickser
In never played with OnEvent(), so I might be totally wrong, but there are some bugs in the API. The major ones are:
1. GetShots() not working, so no info at all about gunshots.
2. Sometimes units can get abnormal high IDs, like 65000+ , those act weird somehow, I read somewhere.
Maybe, those 2 are the same bug, forgot what I really read about it, sorry.

But hit events usually involve gunshots, so maybe there is your problem.

For unit types: Its probably best praxis to call GetAllUnitData() at the start of every turn and avoid any additional API calls that will only get infos GetAllUnitData() already delivered. Pure LUA is a lot faster then the API calls. And in this table you can look up UnitIDs and get their types. I can't remember the exact syntax, sorry again, but it was not that hard.

Posted: Thu Apr 21, 2011 5:51 pm
by poptart911
To answer your first question, multithreadding in this case means that you can put the current process to sleep and wake it up later. StartLongTask makes a function that can made sleep or woken up (a thread). YieldLongTask puts it to sleep and WorkOnLongTasks will wake it back up. The new thread will run only when woken up.

You'll want to use this when you fear that the computations will take longer than 100ms. Be careful though, if you have too many sleeping threads, the game may crash. Dr. Strangebot doesn't use any multithreadding, but there are certainly situations where it would be a good idea. Also if you are having problems with things taking too long, you may want to take another look at what your code is really doing.

As for figuring out whether a radar is detecting a specific unit you could use this code.

Code: Select all

if GetDistance(unit:GetLongitude(), unit:GetLatitude(), radar:GetLongitude(), radar:GetLatitude()) < unit:GetRange()


I think that would be the most simple way to do it. Of course, this won't work for enemy units that aren't discovered yet unless the game is running in full information mode.:D

Posted: Fri Apr 22, 2011 5:44 pm
by Sensoker
Lots of thanks. Really.

Just one question. Which decimal number corresponds, more or less, with the range of a fighter?

Posted: Mon May 07, 2012 12:12 am
by rosa
hi there im new in ere :D

Posted: Mon May 07, 2012 12:33 am
by xander
rosa wrote:hi there im new in ere :D

That's nice. Are you human and planning on contributing to the discussion, or are you going to come back and alter your post later to provide a helpful link to a large helping of spam?

xander