• Register

The near future: Trains are no longer controlled by humans. Instead, artificial intelligence is used to handle traffic. Program the best AI, beat challenges on various maps and watch it fight other AIs in live, online matches!

Forum Thread
VIP (Games : TrAInsported : Forum : General AI questions : VIP) Locked
Thread Options
Apr 27 2013 Anchor

The TestAI at Trainsportedgame.no-ip.org contains this script function:

function ai.foundPassengers(train, passengers)
     if train.passenger and train.passenger:find("VIP") then return nil end
     for k, p in pairs(passengers) do
         if p.name:find("VIP") then
             print("found VIP!")
             if train.passenger then
             return p
     return passengers[1]

However the console outputs this error:
Error occurred when calling function::124: attempt to call method 'find' (a nil value)

where line 124 is:

if train.passenger and train.passenger:find("VIP") then

What is the issue here?

Edited by: Ruoruni

Apr 28 2013 Anchor

The problem is that this is an old function, and ai.foundPassengers has been changed a little. train.passenger used to be just the name of the passenger, but now it's a table which holds the name and the destination of the passenger. Since a table doesn't contain the function "find" it throws the error.

To fix it, try:

if train.passenger and train.passenger.name:find("VIP") then

Edited by: Germanunkol

Reply to thread
click to sign in and post

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.