Jump to content

Change Script properties in the App file, Lua.


josk
 Share

Recommended Posts

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.

Elite Cobra Squad

Link to comment
Share on other sites

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!

Elite Cobra Squad

Link to comment
Share on other sites

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?

Elite Cobra Squad

Link to comment
Share on other sites

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

  • Upvote 1

HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB

Link to comment
Share on other sites

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. :)

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

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.rolleyes.gif

Elite Cobra Squad

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...