gilzoide / godot-lua-pluginscript

Godot PluginScript for the Lua language, currently based on LuaJIT's FFI
https://gilzoide.github.io/godot-lua-pluginscript/topics/README.md.html
MIT License
300 stars 21 forks source link

Scripts Inherited By Scenes All Share Variables #18

Closed Jamtoad closed 2 years ago

Jamtoad commented 2 years ago

Hi its me again, sorry to bother! I noticed today that when a script is tied to a scene, when you instance that scene all of those instanced scenes share variables. So for example if I change a variable for one of the scripts it changes for every scene that has that script.

Is this because I am declaring my variables this way?

Is there a different way I should be declaring variables?

**EDIT Upon doing more reading I realize that this is an issue with godot. I need to make each scene unique from one another. Still researching how to do that.

Thank you and have a wonderful day!


local Test = {}

Test.extends = "KinematicBody2D"

Test.Variable = 60
Jamtoad commented 2 years ago

Turns out it was an issue of using self or not haha. Same as last time I posted an issue. I guess I need to be using self more often.

gilzoide commented 2 years ago

Hi there! Sorry about the delay.

Yeah, anytime you need to access properties or call methods in instances, use self. If you want to really access/change the script table itself, only then you use your Test variable to access stuff. I still have to document this better and create examples of projects/scripts in Lua =/

I'm glad you figured it out ^^ Don't hesitate in asking if you have any more trouble, we'll be happy to help!