Lua information access

Questions and information about using Lua scripting with Storyboard

Moderator: jamiev

Lua information access

Postby cguthrie » Mon Aug 15, 2011 11:04 am

Hi All,

So I'm trying to toggle a button, having an alpha value of 255 represent on and an alpha value of 128 represent off. I'm trying to do this through lua, but I can't seem to test the alpha value from lua. What is the proper syntax for this?

Thanks
Chelsea
cguthrie
 
Posts: 24
Joined: Thu Jun 30, 2011 7:27 pm

Re: Lua information access

Postby jason » Mon Aug 15, 2011 12:03 pm

Hi Chelsea,

First thing is to create a data variable for the alpha value in set it to the context of the control. Then from Lua

Code: Select all
local data = {}

data["layer1.control1.alpha"] = 255

gre.set_data(data)


And that sound be it. The path for the variable could change if you used a different context, but control level is the default.

If you are using the 1.3 you can go the variable in the variable view and right click and select "copy path" and the full path to the variable will be in your clipboard.

Jason
User avatar
jason
 
Posts: 140
Joined: Mon Nov 02, 2009 4:53 pm

Re: Lua information access

Postby cguthrie » Mon Aug 15, 2011 4:11 pm

Hi Jason,

So that tells me how to set the variable, but I am looking to test the variable. and this:

if(data["layer1.control1.alpha"] == 255)

hasn't been workimg. Is there a way to achieve this?

Thanks,
Chelsea
cguthrie
 
Posts: 24
Joined: Thu Jun 30, 2011 7:27 pm

Re: Lua information access

Postby jason » Mon Aug 15, 2011 4:50 pm

So you just want to verify the variable exists?

If so this will do it

Code: Select all
if(data["layer1.control1.alpha"] == nil) then
    print("variable does no exist")
end


There is information here if you want to go a lot deeper
http://lua-users.org/wiki/DetectingUndefinedVariables

If I'm still not answering your question I'll need you to explain more.

Regards,
Jason
User avatar
jason
 
Posts: 140
Joined: Mon Nov 02, 2009 4:53 pm

Re: Lua information access

Postby cguthrie » Mon Aug 15, 2011 5:39 pm

No I want to access/test the value of the variable, I want the same function to toggle both on and off so:

Code: Select all
local data = {}
if data["layer1.control1.alpha"] == 255 then

    data["layer1.control1.alpha"] = 128

else if  (data["layer1.control1.alpha"] == 128) then

    data["layer.control.alpha"] = 255
end

gre.setdata(data)
end


Let me be clear, the code above does not work. The code above is how I thought this would work until I discovered that it does not. I believe that when you create local data = {} data is empty, therefore, Jason, I believe that what you posted will also fail. Am I missing something?

Regards,
Chelsea
cguthrie
 
Posts: 24
Joined: Thu Jun 30, 2011 7:27 pm

Re: Lua information access

Postby jason » Tue Aug 16, 2011 6:31 am

You need to get the data first

Code: Select all
data = {}

data = gre.get_data("layer1.control1.alpha")

if data["layer1.control1.alpha"] == 255 then
    ....


Sorry about that, I was thinking you meant something different so it took a little longer to clue to what you were asking.

Jason
User avatar
jason
 
Posts: 140
Joined: Mon Nov 02, 2009 4:53 pm

Re: Lua information access

Postby cguthrie » Wed Aug 17, 2011 1:36 pm

thanks, no worries.

Chelsea
cguthrie
 
Posts: 24
Joined: Thu Jun 30, 2011 7:27 pm


Return to Lua Scripting

Who is online

Users browsing this forum: No registered users and 0 guests

cron