[Lua] IsVisible Help

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

Moderator: Defcon moderators

User avatar
Ace Rimmer
level5
level5
Posts: 10803
Joined: Thu Dec 07, 2006 9:46 pm
Location: The Multiverse

[Lua] IsVisible Help

Postby Ace Rimmer » Thu Feb 25, 2010 7:54 pm

Per the function list, IsVisible =
IsVisible : unitId, byTeamId : bool

True iff given unit is visible to given team. In full information mode, visibility information about other teams is available. In limited information mode, only visible units are accessible


Lua Guide says:
IsVisible (unitID, teamID)
unitID:IsVisible (teamID)


Every which way I've used this, the game crashes. If understand this correctly, it's this...

IsVisible(unitID[not your own unit], [your own]TeamID), that is, can your own bot see the enemy unit you're referencing.

Even in chat, IsVisible causes a crash. Is it my code or the argument?!

Code: Select all

Defcon 4
        enemyBattleships = {}
        other code logs enemy units every second

...
Defcon 3

   local us = GetOwnTeamID()
   local eb = # enemyBattleships
   if # enemyBattleships > 0 then
      --if enemyBattleships[eb]:IsVisible (us) == true then
         SendChat(enemyBattleships[eb]:IsVisible (us))
      --end
   end
User avatar
roflamingo
level3
level3
Posts: 404
Joined: Fri Jan 19, 2007 10:25 am

Postby roflamingo » Thu Feb 25, 2010 8:17 pm

Can you display boolean values (true/false)? I thought it wouldnt output them.
User avatar
Ace Rimmer
level5
level5
Posts: 10803
Joined: Thu Dec 07, 2006 9:46 pm
Location: The Multiverse

Postby Ace Rimmer » Thu Feb 25, 2010 8:21 pm

I don't know, but even if you can't I've had strings in the SendChat with the if statement un-commented and it still crashed.
Smoke me a kipper, I'll be back for breakfast...
Montyphy
level5
level5
Posts: 6747
Joined: Tue Apr 19, 2005 2:28 pm
Location: Bristol, England

Postby Montyphy » Thu Feb 25, 2010 8:45 pm

Doesn't cause Defcon to crash but SendChat wont accept boolean values. Either use tostring() on the returned value or use print() to output the value.

Are you certain that you're populating enemyBattleships with unitIDs?
Uplink help: Check out the Guide or FAQ.
Latest Uplink patch is v1.55.
User avatar
Ace Rimmer
level5
level5
Posts: 10803
Joined: Thu Dec 07, 2006 9:46 pm
Location: The Multiverse

Postby Ace Rimmer » Thu Feb 25, 2010 9:30 pm

It must be IsVisible causing it to crash because everytime I attempt to use it, Defcon crashes. As soon as I stop, everything works fine.

Code: Select all

   ---[[
   local us = GetOwnTeamID()
   local eb = # enemyBattleships

   if # enemyBattleships > 0 then
      --if enemyBattleships[eb]:IsVisible (us) == true then
         SendChat("yep, more than one BB")
         print(enemyBattleships[eb]:IsVisible(us))
      --end
   end
   --]]


Without the print(), I got my SendChat message. With the print(), crash.
Smoke me a kipper, I'll be back for breakfast...
User avatar
roflamingo
level3
level3
Posts: 404
Joined: Fri Jan 19, 2007 10:25 am

Postby roflamingo » Thu Feb 25, 2010 9:47 pm

Exactly. You can evaluate if a condition == true, but you cannot print out 'true'. You would need an

if blah == true then
SendChat("stuff is true!)
else
SendChat("stuff is false!")
end
Montyphy
level5
level5
Posts: 6747
Joined: Tue Apr 19, 2005 2:28 pm
Location: Bristol, England

Postby Montyphy » Thu Feb 25, 2010 9:50 pm

roflamingo wrote:Exactly. You can evaluate if a condition == true, but you cannot print out 'true'. You would need an

if blah == true then
SendChat("stuff is true!)
else
SendChat("stuff is false!")
end


There's no need to do that when you can do either of the following:

Code: Select all

print(true)


Code: Select all

SendChat(tostring(true))


I recommend both of you create a test bot which is blank template so you can test simple ideas or portions of code. Something like this:

Code: Select all

-- Make require look in this folder for .lua files
package.path = debug.getinfo(1, "S").source:match[[^@?(.*[\/])[^\/]-$]] .."?.lua;".. package.path

-- Load up required files
require "utility"

function OnInit()
   SendChat "/name [Bot]TestBot"
end

function OnTick()
   OnFirstTick()
   OnTick = OnTickReal
   return OnTick()
end

function OnFirstTick()
end

function OnTickReal()
   WorkOnLongTasks()
   
   --only want to do this once
   if GetGameTick() == 60 then
      print(true)
      SendChat(tostring(true))
   end
end

function OnEvent(eventType, sourceID, targetID, unitType, longitude, latitude)
end

function OnShutdown()
end
Uplink help: Check out the Guide or FAQ.

Latest Uplink patch is v1.55.
User avatar
roflamingo
level3
level3
Posts: 404
Joined: Fri Jan 19, 2007 10:25 am

Postby roflamingo » Thu Feb 25, 2010 9:54 pm

Right. I think we both got it :o
User avatar
Ace Rimmer
level5
level5
Posts: 10803
Joined: Thu Dec 07, 2006 9:46 pm
Location: The Multiverse

Postby Ace Rimmer » Thu Feb 25, 2010 10:03 pm

Code: Select all

   if # enemyBattleships > 0 then
      for i, unit in ipairs(enemyBattleships) do
         if unit:IsVisible (us) == true then
            SendChat("yep, more than one BB")
            print(true)
         end
      end
   end

Still crashes
Smoke me a kipper, I'll be back for breakfast...
User avatar
roflamingo
level3
level3
Posts: 404
Joined: Fri Jan 19, 2007 10:25 am

Postby roflamingo » Thu Feb 25, 2010 10:05 pm

Why do you need to print(true)? You already know the condition is true... you could just print("true")...couldn't you?
User avatar
Ace Rimmer
level5
level5
Posts: 10803
Joined: Thu Dec 07, 2006 9:46 pm
Location: The Multiverse

Postby Ace Rimmer » Thu Feb 25, 2010 10:06 pm

roflamingo wrote:Why do you need to print(true)? You already know the condition is true... you could just print("true")...couldn't you?

I suppose that bit is redundant now. :P
Smoke me a kipper, I'll be back for breakfast...
User avatar
roflamingo
level3
level3
Posts: 404
Joined: Fri Jan 19, 2007 10:25 am

Postby roflamingo » Thu Feb 25, 2010 10:08 pm

Montyphy wrote:I recommend both of you create a test bot which is blank template so you can test simple ideas or portions of code.


I think that's a great idea... but I have ~500 lines of code that work really well. It's when I elaborate into more complex things that things start to bog down...

That and I'm learning LUA as I go along.

I really appreciate your teaching and patience... you have no obligation to be as helpful as you are.
Montyphy
level5
level5
Posts: 6747
Joined: Tue Apr 19, 2005 2:28 pm
Location: Bristol, England

Postby Montyphy » Thu Feb 25, 2010 10:17 pm

Ace, what is the table populated with?

roflamingo wrote:Why do you need to print(true)? You already know the condition is true... you could just print("true")...couldn't you?


Was just a simple example to show that it handled boolean values without causing a problem :P
Uplink help: Check out the Guide or FAQ.

Latest Uplink patch is v1.55.
User avatar
Ace Rimmer
level5
level5
Posts: 10803
Joined: Thu Dec 07, 2006 9:46 pm
Location: The Multiverse

Postby Ace Rimmer » Thu Feb 25, 2010 10:23 pm

The enemyBattleships table is populated with unitID's of BB's other than mine. Perhaps I need FleetIDs in there instead of unitID's

This code happens every tick from Defcon 4 down:

Code: Select all

function CheckEnemyUnits()
   StartLongTask(function()
   local enemyUnits = GetAllUnits()   
   local us = GetOwnTeamID()
   for i, unit in ipairs(enemyUnits) do
      if unit:GetTeamID() ~= us then
         if  unit:GetUnitType () == "Silo" then
            local items = SetES (enemySilos)
            if items[unit] == nil then
               table.insert(enemySilos, unit)
               table.insert(targetCities, 1, unit)
               table.insert(silotargetCities, 1, unit)
            end
         elseif  unit:GetUnitType () == "AirBase" then
            local items = SetEA (enemyAirbases)
            if items[unit] == nil then
               table.insert(enemyAirbases, unit)
               table.insert(targetCities, 10, unit)
            end
         elseif  unit:GetUnitType () == "RadarStation" then
            local items = SetER (enemyRadars)
            if items[unit] == nil then
               table.insert(targetCities, 1, unit)
               table.insert(enemyRadars, unit)
               table.insert(silotargetCities, 1, unit)
            end
         elseif  unit:GetUnitType () == "BattleShip" then
            local items = SetEB (enemyBattleships)
            if items[unit] == nil then
               table.insert(enemyBattleships, unit)
            end
         elseif  unit:GetUnitType () == "Carrier" then
            local items = SetEC (enemyCarriers)
            if items[unit] == nil then
               table.insert(enemyCarriers, unit)
            end
         elseif  unit:GetUnitType () == "Sub" then
            local items = SetESb (enemySubs)
            if items[unit] == nil then
               table.insert(enemySubs, unit)
            end
         end
      end
   end
   YieldLongTask()
   --SendChat("Silos:" .. # enemySilos .. " Airbases:" .. # enemyAirbases .. " Radars:" .. # enemyRadars .. " BBs:" .. # enemyBattleships .. " CVs:" .. # enemyCarriers)
   end)
end         
User avatar
NeoThermic
Introversion Staff
Introversion Staff
Posts: 6256
Joined: Sat Mar 02, 2002 10:55 am
Location: ::1
Contact:

Postby NeoThermic » Thu Feb 25, 2010 11:43 pm

roflamingo wrote:I really appreciate your teaching and patience... you have no obligation to be as helpful as you are.


Lies, we've got him locked in the basement with just the forums as an access to the outside world. If he answers, he gets food. If he does not, we don't feed him for one day... ;)

NeoThermic

Return to “AI Bots”

Who is online

Users browsing this forum: No registered users and 7 guests