Squirrel questions ...

Discuss the new AI features ("NoAI") introduced into OpenTTD 0.7, allowing you to implement custom AIs, and the new Game Scripts available in OpenTTD 1.2 and higher.

Moderator: OpenTTD Developers

krinn
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 29 Dec 2010 19:36

Re: Squirrel questions ...

Post by krinn »

3iff wrote:I never thought of that. It works (unfortunately the function is in runaway mode as I can't stop it reprocessing the function...)

It would have also helped had I used square brackets in one place, numberlist[] not numberlist() !!

Thanks.

To get a value back from the function I needed to use:

j = functionname(numberlist,jj) and a return j; in the function. (of course you knew that...)

It finally does what I need. Hooray! (I hope)
Not really what Albert suggest you

Code: Select all

function other(members) { members.push("four!"); }
function that() { local memberlist = ["one", "two", "three"]; print("size: "+memberlist.len()); other(memberlist); print("size: "+memberlist.len()); }
Keep in mind you are passing the instance of the array, so any change in it, will change the array when you're back from the call (so in the sample, your array will get a new "four!").
User avatar
3iff
Tycoon
Tycoon
Posts: 1093
Joined: 21 Oct 2005 09:26
Location: Birmingham, England

Re: Squirrel questions ...

Post by 3iff »

Well, I'm simply reading the array, not changing it, it's a static array of names.
What I have works exactly as expected even if I might have misunderstood what I was told.

I'm thinking that your code adds "four" to that list? I'm never going to be doing that...

(squirrel is HARD!) :?
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: Squirrel questions ...

Post by Zuu »

3iff wrote:And a separate question, can I do this, to just extract vehicles making less than £1000 last year and less than £500 this year? Does the second filter work on the first filter?

vehicles = AIVehicleList_Group(route.group);
vehicles.Valuate(AIVehicle.GetProfitLastYear);
vehicles.KeepBelowValue(1000);
vehicles.Valuate(AIVehicle.GetProfitThisYear);
vehicles.KeepBelowValue(500);
Yes.

The first KeepBelowValue(1000) will remove all items from the list that have value >= 1000. So any subsequent filter will only operate on the remaining items in the list.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
User avatar
3iff
Tycoon
Tycoon
Posts: 1093
Joined: 21 Oct 2005 09:26
Location: Birmingham, England

Re: Squirrel questions ...

Post by 3iff »

Thanks Zuu. I wasn't sure if the second filter was working so I remmed it out and did a manual check via an IF. I'll pop it back as it's a neater way of doing it.
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 7 guests