• 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
need a little help please (Games : TrAInsported : Forum : General AI questions : need a little help please) Locked
Thread Options
Apr 16 2014 Anchor

First, thank you for a cool game. I haven't had this much fun in a long time.

Now, to my problem. I can set up a counter ..n = n + 1 to either drop passengers or change directions, but it only works for ALL the trains (trAIns ?) or passengers.
How do I set the counter to individual trains or passengers ?

Apr 20 2014 Anchor

You should add a (global) table which saves stats about your trains.
Each trains has a unique train name, so what you can do is the following:

data = {}

function ai.newTrain(train)
    data[train.name] = {}   -- create a new table for each new train
    data[train.name].count = 1

function ai.chooseDirection(train, directions)
    data[train.name].count = data[train.name].count + 1
    print(train.name, data[train.name].count)

Since I index the data table using the train's name I can save separate data for each train, using only one global table.

Hope this helped...

Apr 22 2014 Anchor

I'll give this a try, and let you know how it goes.

Yup, worked like a charm. Many thanks...

Apr 24 2014 Anchor

Glad it worked, good luck with your AI!

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.