AggrorJorn Posted July 2, 2013 Share Posted July 2, 2013 So I have been working on a flowgraph GUI and I am running in to an issue. When you click a button you can connect to a gui collection that hides all gui elements (in this example, 3 buttons) of a certain category. Everything works fine except when I add another gui collection to the scene. Works fine.. Once I add a new gui collection to the scene (also 3 buttons in the image), all 6 buttons hide the second gui collection, although the first 3 buttons are not connected to the second GUI collection. The problem must lie somewhere in the buttons array that I use to store the buttons. Buttons are added to this array on startup by looking through a gui collections children. I tried using both Script.buttons = {} --in start --store children as buttons self.childrenCount = self.entity:CountChildren() for i=1, self.childrenCount, 1 do self.buttons[i] = self.entity:GetChild(i-1) end as well as: local buttons = {} --in start --store children as buttons self.childrenCount = self.entity:CountChildren() for i=1, self.childrenCount, 1 do buttons[i] = self.entity:GetChild(i-1) end Any ideas? Quote Link to comment Share on other sites More sharing options...
Rick Posted July 3, 2013 Share Posted July 3, 2013 For me I guess I'd have to see the entire project. I'm willing to check it out if you want. You can PM me the project or post it here. I guess I can't tell from just what you posted. 1 Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted July 3, 2013 Author Share Posted July 3, 2013 Rick found the solution to this problem. Declaring lua tables like this: Script.myTable = {} --or local myTable = {} somehow makes them global and thus they will overwrite each other when the script is attached to multiple objects. Rick found out that you can solve this as follow: Script.myTable = nil function Script:Start() self.myTable = {} end Quote Link to comment Share on other sites More sharing options...
Rick Posted July 3, 2013 Share Posted July 3, 2013 I would be curious to know why this is the case thought. I wouldn't think it should be. Quote Link to comment Share on other sites More sharing options...
Admin Posted July 3, 2013 Share Posted July 3, 2013 Generally, I find I need script values that are shared among the class, and others that are unique to each class. For example, you might have some object initialization stuff you only want to perform once, not for every single instance of the script. The flowgraph stuff you're doing looks interesting. Quote Link to comment Share on other sites More sharing options...
Rick Posted July 3, 2013 Share Posted July 3, 2013 So like static/shared variables? That makes sense, but why is it only tables created outside any function act like this and not all Script. variables? [edit] I tested an exposed variable like Script.health and set it's value differently between 4 different entities, but now that I say this when the game loads you must be making the same named variable behind the scenes for self so that self.health is unique now per instance. Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted July 3, 2013 Author Share Posted July 3, 2013 Josh posted the following in another topic, but it is relevant to this topic. Shared across all instances of the script: Script.mytable = {} function Script:Start() end Unique for each instance: function Script:Start() self.mytable = {} end Global variable: mytable = {} function Script:Start() end Global variable: function Script:Start() mytable = {} end Local variable: local mytable = {} function Script:Start() end Local variable: function Script:Start() local mytable = {} end Quote Link to comment Share on other sites More sharing options...
beo6 Posted July 3, 2013 Share Posted July 3, 2013 That is a bit odd. so you define the lua parameters like these: Script.myfloat = 12--float "myfloat" and they are defined for all instances? why can i change the parameters in the script-tab differently for each instance in the Editor? Quote Link to comment Share on other sites More sharing options...
Rick Posted July 3, 2013 Share Posted July 3, 2013 @beo6 The only thing I can think of is when the variable is exposed and given a value (at startup) Josh is making the exact same variable name but for self (or the actual entity instead of Script). That would make it unique per entity instance then. Some magic behind the doors. I haven't tested but when accessing from another script I'm curious what entity.script.myfloat would return. Would that return the global script variable instead of the unique instance variable? I would think so. In which case making getters to return self.myfloat would be what is needed to get the unique instanced value so you could call entity.script:GetMyFloat(). Maybe I'll test later today. Quote Link to comment Share on other sites More sharing options...
Admin Posted July 3, 2013 Share Posted July 3, 2013 I should have explained that better...when you have exposed variables like that, they are initially set all the same, but the editor will adjust them post-loading. Floats and integers are never shared, because they are just variables: local a = 1 local b = a a=2 print( b ) --Prints "1" However, tables do not get copied when they are assigned: local a = {} a.value=1 local b = a a.value=2 print( b.value ) --Prints "2" Quote Link to comment Share on other sites More sharing options...
Rick Posted July 3, 2013 Share Posted July 3, 2013 Ah, so tables are treated more like pointers in that sense. I see. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.