Can't call Sleep() from withing _get() metamethod

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

Post Reply
User avatar
Zutty
Director
Director
Posts: 565
Joined: 22 Jan 2008 16:33

Can't call Sleep() from withing _get() metamethod

Post by Zutty »

Hi all,

I have found that I am unable to call AIController.Sleep() from within the _get() metamethod of a class. Is this expected behaviour?

The following snippet should demonstrate this (tested in r19055)

Code: Select all

class foo {
	function _get(x) {
		::AIController.Sleep(1)
	}
}
foo().bar
I cant see any reason why this would be forbidden, unless I'm missing something. Please tell me this is a bug, that you can fix before 1.0 is released! :D Please please please!

As for why I want this, I'm trying to create a dynamic Proxy class for a little bit of AOP, to streamline my codebase a little bit.

Thanks very much
PathZilla - A networking AI - Now with tram support.
Rubidium
OpenTTD Developer
OpenTTD Developer
Posts: 3815
Joined: 09 Feb 2006 19:15

Re: Can't call Sleep() from withing _get() metamethod

Post by Rubidium »

If I recall correctly executing those metamethods are implemented by 're-entering' the virtual machine (think of recursion) via a piece of C++ code. A we cannot suspend the C++ code we cannot suspend the virtual machine if called in that way, as such no sleeps or docommands are allowed. Changing this means basically rewriting the Squirrel implementation, which is very unlikely to happen..
User avatar
Zutty
Director
Director
Posts: 565
Joined: 22 Jan 2008 16:33

Re: Can't call Sleep() from withing _get() metamethod

Post by Zutty »

Ah damn, nevermind. I'll find some other way of doing it then. Thanks Rubidium.
PathZilla - A networking AI - Now with tram support.
Blustuff
Engineer
Engineer
Posts: 112
Joined: 21 Aug 2008 09:37
Location: France

Re: Can't call Sleep() from withing _get() metamethod

Post by Blustuff »

The SquirrelVM is awful.
User avatar
SirkoZ
Tycoon
Tycoon
Posts: 1518
Joined: 06 Mar 2004 23:51
Location: The sunny side of Alps

Re: Can't call Sleep() from withing _get() metamethod

Post by SirkoZ »

Blustuff wrote:The SquirrelVM is awful.
Please, provide a better one. It will be greatly appreciated.
Blustuff
Engineer
Engineer
Posts: 112
Joined: 21 Aug 2008 09:37
Location: France

Re: Can't call Sleep() from withing _get() metamethod

Post by Blustuff »

SirkoZ wrote:Please, provide a better one. It will be greatly appreciated.
I'm on it. 'will take one year or two.
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 5 guests