[LUA] Two doubts

Come in here to talk about your sky-net style world-destroying super bots!

Moderator: Defcon moderators

Sensoker
level0
Posts: 4
Joined: Wed Apr 13, 2011 6:02 pm

[LUA] Two doubts

Postby Sensoker » Wed Apr 13, 2011 6:14 pm

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!
User avatar
trickser
level5
level5
Posts: 1823
Joined: Thu Mar 06, 2008 2:15 pm
Location: The Senate ; GMT+1
Contact:

Postby trickser » Wed Apr 13, 2011 11:04 pm

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.
Sensoker
level0
Posts: 4
Joined: Wed Apr 13, 2011 6:02 pm

Postby Sensoker » Mon Apr 18, 2011 10:02 pm

Thanks!

Another question. Inside the OnEvent function, which would mean the targetID, sourceID and object type?
User avatar
Ace Rimmer
level5
level5
Posts: 10803
Joined: Thu Dec 07, 2006 9:46 pm
Location: The Multiverse

Postby Ace Rimmer » Mon Apr 18, 2011 10:25 pm

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
Smoke me a kipper, I'll be back for breakfast...
Sensoker
level0
Posts: 4
Joined: Wed Apr 13, 2011 6:02 pm

Postby Sensoker » Mon Apr 18, 2011 10:49 pm

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..?
User avatar
trickser
level5
level5
Posts: 1823
Joined: Thu Mar 06, 2008 2:15 pm
Location: The Senate ; GMT+1
Contact:

Postby trickser » Tue Apr 19, 2011 5:52 pm

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.
User avatar
poptart911
level1
level1
Posts: 33
Joined: Thu Jan 13, 2011 6:04 pm
Location: Iowa, US
Contact:

Postby poptart911 » Thu Apr 21, 2011 5:51 pm

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
Sensoker
level0
Posts: 4
Joined: Wed Apr 13, 2011 6:02 pm

Postby Sensoker » Fri Apr 22, 2011 5:44 pm

Lots of thanks. Really.

Just one question. Which decimal number corresponds, more or less, with the range of a fighter?
rosa
level0
Posts: 1
Joined: Sun May 06, 2012 6:25 pm

Postby rosa » Mon May 07, 2012 12:12 am

hi there im new in ere :D
User avatar
xander
level5
level5
Posts: 16865
Joined: Thu Oct 21, 2004 11:41 pm
Location: Riverside, CA, USA
Contact:

Postby xander » Mon May 07, 2012 12:33 am

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

Return to “AI Bots”

Who is online

Users browsing this forum: No registered users and 1 guest