Search the Community
Showing results for tags 'table'.
-
Something weird is happening. I have two objects with the scame script on them. Here is the code: Script.enabled=0 --bool "enabled" Script.int=0 Script.tab={1} function Script:UpdateWorld() System:Print("------------starts "..self.entity:GetKeyValue("name")) System:Print("int="..self.int) System:Print("#="..#self.tab) System:Print("[#]="..self.tab[#self.tab]) if not self.enabled then return end self.int=self.int+1 self.tab[#self.tab+1]=math.random(1,9) System:Print("-----------END "..self.entity:GetKeyValue("name")) end It has boolean variable which is set to true for one entity and to false for another entity in the editor. it also has one number variable (int) and one table (tab). Script with "enabled" entity ads +1 to int variable and one extra table element with random value each update. And here is what I get in output: ------------starts Pivot 1 (enabled) int=0 #=1 [#]=1 -----------END Pivot 1 (enabled) ------------starts Pivot 2 (disabled) int=0 #=2 [#]=4 ------------starts Pivot 1 (enabled) int=1 #=2 [#]=4 -----------END Pivot 1 (enabled) ------------starts Pivot 2 (disabled) int=0 #=3 [#]=8 ------------starts Pivot 1 (enabled) int=2 #=3 [#]=8 -----------END Pivot 1 (enabled) ------------starts Pivot 2 (disabled) int=0 #=4 [#]=7 ------------starts Pivot 1 (enabled) int=3 #=4 [#]=7 -----------END Pivot 1 (enabled) ------------starts Pivot 2 (disabled) int=0 #=5 [#]=9 ... (Added space after each update for easier reading) As you can see int variable increases in "enabled" entity and doesn't change in "disabled". Also disabled entity doesn't print last ("---END") line, so it is really disabled. But for some reason the table changes for both of those entities. It has same amount of elements and the last element is the same (it was generated randomly) for both scripts. Can you please explain me what is going on here?