Possible to have a workaround for this?
[CODE] pls = 0
for i =1, 14 do
local pls = pls + 35
local bp1 = vgui.Create( "DButton", p1_base )
bp1:SetSize(150, 33)
bp1:SetPos(12,pls)
bp1:SetText(propButton["p1_B"..i..""])
bp1:SetTextColor(ButtonTextColor)
bp1.Paint = function()
surface.SetDrawColor(19, 105, 153)
surface.DrawRect( 0, 0, bp1:GetWide(), bp1:GetTall() )
end[/CODE]
Basically, I'm trying to prevent having to create many lines you can see, local bp1 = ... but this is being executed 14 times, all with the same variable of "bp1" so changing one thing changes them all. any work around for this? is it possible to create a random variable each time it executes?
First of all, let's fix the pls variable to actually do what you need it to do:
[code]
local pls = 0
for i =1, 14 do
pls = pls + 35
local bp1 = vgui.Create( "DButton", p1_base )
bp1:SetSize(150, 33)
bp1:SetPos(12,pls)
bp1:SetText(propButton["p1_B"..i..""])
bp1:SetTextColor(ButtonTextColor)
bp1.Paint = function()
surface.SetDrawColor(19, 105, 153)
surface.DrawRect( 0, 0, bp1:GetWide(), bp1:GetTall() )
end
// ...
end[/code]
You were localizing the variable inside the loop, so it would override the variable outside of the loop, not changing it.
Now the question is, what exactly you are asking for:
1) Change the buttons in any way after they are created?
2) Change the buttons when they are created in your code, in which case, what exactly are you trying to do?
[QUOTE=Robotboy655;50314997]First of all, let's fix the pls variable to actually do what you need it to do:
[code]
local pls = 0
for i =1, 14 do
pls = pls + 35
local bp1 = vgui.Create( "DButton", p1_base )
bp1:SetSize(150, 33)
bp1:SetPos(12,pls)
bp1:SetText(propButton["p1_B"..i..""])
bp1:SetTextColor(ButtonTextColor)
bp1.Paint = function()
surface.SetDrawColor(19, 105, 153)
surface.DrawRect( 0, 0, bp1:GetWide(), bp1:GetTall() )
end
// ...
end[/code]
You were localizing the variable inside the loop, so it would override the variable outside of the loop, not changing it.
Now the question is, what exactly you are asking for:
1) Change the buttons in any way after they are created?
2) Change the buttons when they are created in your code, in which case, what exactly are you trying to do?[/QUOTE]
:speechless: that's all I wanted, simple fix, didn't even notice that I localized it inside of the loop.
thank you. :) :v:
Sorry, you need to Log In to post a reply to this thread.