josk Posted July 26, 2013 Share Posted July 26, 2013 In the App file I create some instances of a model, I then attach the square Lua file. In the Lua file there is Script.block = 0. How can i change that value using code in the App file, or can you? for a =1,10 do for b =1,10 do land = tolua.cast(land:Instance(),"Model") land:SetScript("Scripts/Player/square.lua") land:SetPosition(a,0,B) land.block = land.block + 1 -- this does not do it end end Can someone set me straight. Quote Elite Cobra Squad Link to comment Share on other sites More sharing options...
AggrorJorn Posted July 26, 2013 Share Posted July 26, 2013 When you debug with breakpoints, is land having a block variable? Try also initializing de the block value in the start function of the script. Alternatively, you can also set keys. Quote Link to comment Share on other sites More sharing options...
Rick Posted July 26, 2013 Share Posted July 26, 2013 land.script.block = 5 for functions land.script:MyFunction() Quote Link to comment Share on other sites More sharing options...
josk Posted July 26, 2013 Author Share Posted July 26, 2013 I think they might be a problem with the second For command, when I set a breakpoint it only shows the second For. If I only put one For in it works but the entities are not in the right position then. Some math might get rid of the second For! Quote Elite Cobra Squad Link to comment Share on other sites More sharing options...
josk Posted July 27, 2013 Author Share Posted July 27, 2013 land.script.block is given the final number as in 10 for a = 1,10 I need each Land to be given the numbers 1 through 10. Also I need the numbers 1 through 50 by using for a = 1,10 do for b = 1,5 do Any ideas? Quote Elite Cobra Squad Link to comment Share on other sites More sharing options...
shadmar Posted July 27, 2013 Share Posted July 27, 2013 If you make a "class" for it like this local land = Model:Box() self.myblocks = {} local count = 0 for a =1,10 do for b =1,10 do count=count+1 local tile = tolua.cast(land:Instance(),"Model") self.myblocks[tile] = { land = tile, x = a, z = b, idx = count } tile:SetPosition(a,0,B) end end Then you can access it and it's "members" in any external lua script like this : for k,v in pairs(App.myblocks) do print (v.idx) v.land:SetPosition(0,0,0) end 1 Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
Josh Posted July 27, 2013 Share Posted July 27, 2013 Basically, the debugger does not reveal the attached script table because it's returning debug info from the C++ class, not from Lua. This makes a really good case for including the Lua table in the entity debug info. In any case, you can access all the script values directly as shown below: land:SetScript("Scripts/Player/square.lua") land:SetPosition(a,0,B) land.script.block = land.script.block + 1 -- this does it! Having all the variables and functions in one script table associated with the entity makes it easier to call standard script functions on other entities without knowing what their own scripts do. For example, you can check to see if the attached script contains a function called "Kill" and call it, without knowing or caring what it does. Be sure to check to make sure entity.script is not nil, which is the case until a script is attached: if entity.script~=nil then if type(entity.script.Kill)=="function" then entity.script:Kill() end end BTW, using the "lua" forum tag instead of "code" will give you Lua syntax highlighting. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
josk Posted July 28, 2013 Author Share Posted July 28, 2013 Thanks I have now got it working and understand Lua that bit more. I initially had the For code in a script which was attached to many entities but then realised that code would be getting called 50 times. So it only needs to be in the App script. I will remember the Lua forum tag, learning new things all the time. Quote Elite Cobra Squad 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.