Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What is wrong with this decal-changing script?

Asked by
iAviate 20
10 years ago

Hi, So i'm writing this script that changes the decal texture asset ID of a part called "Screen". I've made loads of different stringvalues (one, two, three) which each have their own asset ID link (eg. http://www.roblox.com/asset/?id=238110849) i'm quite sure the links are ok. The hierarchy is:

Model, one, two, three, four, five, six, seven, eight, Part (ClickDetector, Script), Sign (PointLight, Decal)

Here's the script:

01isOn = 0
02local a=script.Parent.Parent.one.Value
03local b=script.Parent.Parent.two.Value
04local c=script.Parent.Parent.three.Value
05local d=script.Parent.Parent.four.Value
06local e=script.Parent.Parent.five.Value
07local f=script.Parent.Parent.six.Value
08local g=script.Parent.Parent.seven.Value
09local h=script.Parent.Parent.eight.Value
10local sign=script.Parent.Parent.Sign.Decal.Texture
11 
12function three()
13do sign=""..a
14    isOn=2
15end
View all 62 lines...

I know it's unnecessarily long but I made the original a while ago and just edited that.

0
There's nothing in the output/script analysis... iAviate 20 — 10y

3 answers

Log in to vote
2
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

You change the variable sign, but only the variable sign.

All that does is overwrite sign with the new texture. That doesn't change the texture of script.Parent.Parent.Sign.Decal.

You have to explicitly change a property to change the property:

1local decal = script.Parent.Parent.Sign.Decal
2 
3......
4 
5decal.Texture = f -- or whatever else here

Let's fix this code, though. Instead of having a bunch of variables, make a list:

01local list = {
02    script.Parent.Parent.one.Value,
03    script.Parent.Parent.two.Value,
04    script.Parent.Parent.three.Value,
05    script.Parent.Parent.four.Value,
06    script.Parent.Parent.five.Value,
07    script.Parent.Parent.six.Value,
08    script.Parent.Parent.seven.Value,
09    script.Parent.Parent.eight.Value
10}

Now it's easy to do the rest:

01local shown = 1
02 
03-- Advance to the next one
04function advance()
05    shown = shown + 1 -- Got to the next one
06    if shown > #list then
07        -- I'm past the end -- start over at 1
08        shown = 1
09    end
10    -- (or you can fiddle with mods to get this to one line of code)
11end
12 
13-- Show the currently selected slide
14function show()
15    decal.Texture = list[shown]
View all 23 lines...
Ad
Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
10 years ago

Your problem is that you're attempting to edit a property directly from a variable

This won't work, you have to make the variable the object that the property is tied to, then edit the variable by indexing the property.

Also, your script has so many unnecessary aspects to it. Just make a table containing all of the values, then use your int variable to index the table.

01local num =  0
02local sign = script.Parent.Parent.Sign.Decal
03local vals = { --Table full of all the values
04script.Parent.Parent.one,
05script.Parent.Parent.two,
06script.Parent.Parent.three,
07script.Parent.Parent.four,
08script.Parent.Parent.five,
09script.Parent.Parent.six,
10script.Parent.Parent.seven,
11script.Parent.Parent.eight
12}
13 
14function incrementDecal()
15    if num == #vals + 1 then num = 0 end --reset if it's at limit
View all 22 lines...
0
BlueTaslem keeps ninja'ing me. Goulstem 8144 — 10y
Log in to vote
0
Answered by 10 years ago

Your script is just over-complicated, which makes it easier to get errors. It would be much simpler to store all the string values into a table, and then having a variable that gets incremented by 1 every time the button is clicked. That way, you can use that variable to get the corresponding element in the table. Like so:

01local Index = 1 --This is the index variable. It will be used to get the corresponding element from the table below
02local Textures = { --This table contains the textureId's for the decals. You can also replace the "script.Parent.Parent.one.Value" with the actual value of One, and do the same for the rest of them
03    script.Parent.Parent.one.Value;
04    script.Parent.Parent.two.Value;
05    script.Parent.Parent.three.Value;
06    script.Parent.Parent.four.Value;
07    script.Parent.Parent.five.Value;
08    script.Parent.Parent.six.Value;
09    script.Parent.Parent.seven.Value;
10    script.Parent.Parent.eight.Value;
11}
12local Sign=script.Parent.Parent.Sign.Decal --The sign variable has to be the decal, not the texture of the decal because the texture of the decal is what you're trying to change. If Sign was the decal's texture, then whenever you said "Sign = ...", that would change the variable, not the texture
13 
14function onClicked()
15    Sign.Texture = Textures[Index] --This sets the textureId of the decal to the Index'th element of the table "Textures"
View all 23 lines...

Hope this helped!

0
Thanks so much! iAviate 20 — 10y

Answer this question