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 ). 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!
[LUA] Two doubts
Moderator: Defcon moderators
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.
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.
- Ace Rimmer
- level5
- Posts: 10803
- Joined: Thu Dec 07, 2006 9:46 pm
- Location: The Multiverse
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
http://www.corsix.org/defcon_luabot/doc ... fn-OnEvent
Smoke me a kipper, I'll be back for breakfast...
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..?
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.
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.
- poptart911
- level1
- Posts: 33
- Joined: Thu Jan 13, 2011 6:04 pm
- Location: Iowa, US
- Contact:
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.
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.
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.
Who is online
Users browsing this forum: No registered users and 25 guests