-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[VSCRIPT] Class defined in the script' scope is not accessible in another class in the same scpoe #173
Comments
This is the expected behaviour. The scope your script is running is not a delegate to your classes for them to fallback to, but every context falls back to the root table (since Squirrel 3.0). Scripts executed inside entities are placed in a table in the root table. Assume ::printl <- function(s) { print( s + "\n" ) }
::T <-
{
A = {}
B = { function fn() { printl( A ) } }
C = class {}
D = class { function fn() { printl( C ) } }
} There are no delegations here. For tables to access their 'siblings' inside A <- {}
B <- { function fn() { printl( A ) } }.setdelegate( this ) Now For classes, you will have to inherit, and access the base class with C <- class {}
D <- class extends C { function fn() { printl( base ) } } Class inheritance is more restrictive, so you can simply declare the variables they need to access using class Point {}
local Point = Point;
class Rectangle
{
constructor()
{
printl( Point() )
}
} Or alternatively reference the other class in a member variable: class Point {}
class Rectangle
{
Point = Point;
constructor()
{
printl( Point() )
}
} Mapbase's implementation is only about how the engine accesses the Squirrel VM. The language itself is not any different. |
Thank you for the clarifications and examples. |
…apbase-source#173) Corrected zombie variant sounds issues Approved-by: 1upD
Description
I found a strange behavior of the execution context in a script.
The following example works fine when it is executed directly in squirrel 3.1, but it fails when it is executed in the game with the following message AN ERROR HAS OCCURRED [the index 'Point' does not exist]
Steps to reproduce
Steps to reproduce the strange behavior:
Expected behavior
The expected behavior is to run the map and the Rectangle class is successfully instantiated.
Additional context, that may help for better understanding the problem
After hours of reading, debugging and testing I reproduce the same error in pure squirrel (v3.1), and it looks like the core of the problem should be in the execution context.
The text was updated successfully, but these errors were encountered: