I've noticed that a number of people are using rawin, rawset and rawget in their AI's, and as far as I know, not using them hasn't restricted me in any way. I was just wondering what they did and if using them would help my AI in some way?
Sir Bob
raw(in/set/get)
Moderator: OpenTTD Developers
raw(in/set/get)
Witty Signature!

Re: raw(in/set/get)
The "raw" accessors ignore delegation; what you might think of as inheritance in general OOP. I think most people use tables as simple data structures though, so I doubt most people are actually making use of this functionality.
Its probably a combination of personal preference or perhaps the lack of documentation for squirrel combined with a bit of cargo-cult programming (i.e. where a programmer copies an entire snippet of another's code verbatim, without fully understanding it!).
TBH I did it myself... at first I thought that rawin etc... was the only way to work with tables, and now I just can't be bothered to change it!!
Its probably a combination of personal preference or perhaps the lack of documentation for squirrel combined with a bit of cargo-cult programming (i.e. where a programmer copies an entire snippet of another's code verbatim, without fully understanding it!).
TBH I did it myself... at first I thought that rawin etc... was the only way to work with tables, and now I just can't be bothered to change it!!

PathZilla - A networking AI - Now with tram support.
Re: raw(in/set/get)
I think you are right there Zutty.
Have you found an alternative to rawin? Rawget isn't really needed (table.rawget("foobar") is equal to table["foobar"] as long as you don't use inheritance). For rawset I'm not really sure. I think table["foobar"] = 3; doesn't work if table doesn't have an index foobar yet. Rawset creates a new index if it doesn't exist yet.Zutty wrote:TBH I did it myself... at first I thought that rawin etc... was the only way to work with tables, and now I just can't be bothered to change it!!
Re: raw(in/set/get)
To create a slot you use the <- operator. E.g. table["foobar"] <- 3;Yexo wrote:I think you are right there Zutty.Have you found an alternative to rawin? Rawget isn't really needed (table.rawget("foobar") is equal to table["foobar"] as long as you don't use inheritance). For rawset I'm not really sure. I think table["foobar"] = 3; doesn't work if table doesn't have an index foobar yet. Rawset creates a new index if it doesn't exist yet.Zutty wrote:TBH I did it myself... at first I thought that rawin etc... was the only way to work with tables, and now I just can't be bothered to change it!!
I am fairly sure that rawin has an equivalent "in" operator, which is used like so: if ("foobar" in table) {}. Dont quote me on this though!
PathZilla - A networking AI - Now with tram support.
Who is online
Users browsing this forum: No registered users and 3 guests