|
| 16 Feb 2015 04:01 PM |
I'm having trouble on iterating through the table I want it so when you click the 'Next' button it change Type's text to "Wizard" And then when you click Next again it will go back to the begin. Also for the Previous. Since it is currently at Villager, when they click Previous It will go to Wizard, then when they click again it goes to Villager.
How would I get it to iterate through ClothingTable this way?
local Player = game.Players.LocalPlayer local Char = Player.Character local Frame = script.Parent local Next = Frame.Next local Previous = Frame.Previous local Type = Frame.Type
local ClothingTable = {"Villager", "Wizard"}
Next.MouseButton1Down:connect(function() end)
Previous.MouseButton1Down:connect(function() end)
"I like to program." - Bosswalrus |
|
|
| Report Abuse |
|
|
|
| 16 Feb 2015 04:03 PM |
This is in a LocalScript, and Filtering Enabled is on. But I want it so only the Player can see the Text, not all the Players.
"I like to program." - Bosswalrus |
|
|
| Report Abuse |
|
|
|
| 16 Feb 2015 04:16 PM |
Bump.
"I like to program." - Bosswalrus |
|
|
| Report Abuse |
|
|
|
| 16 Feb 2015 04:21 PM |
local Player = game.Players.LocalPlayer local Char = Player.Character local Frame = script.Parent local Next = Frame.Next local Previous = Frame.Previous local Type = Frame.Type
local ClothingTable = {"Villager", "Wizard"} -[==[ In a table, theres an Index, and it's Variable(Value). The brackets containing a number is an Index, The String attached to it, is a Variable, which says that Index 1's Value is "Villager". ClothingTable = { [1] = "Villager", [2] = "Wizard" } ]==] local CurrentType = 1 -- The CurrentType is "Villager"
Next.MouseButton1Down:connect(function() CurrentType = CurrentType % #ClothingTable + 1 --Adds by 1, returns back to 1 if the CurrentType's value is bigger than all the Index in the "ClothingTable" Type.Text = ClothingTable[ CurrentType ] -- Displays the Current Type end)
Previous.MouseButton1Down:connect(function() CurrentType = ( CurrentType - 1 >= 1 and CurrentType - 1 or #ClothingTable ) Type.Text = ClothingTable[ CurrentType ] end) |
|
|
| Report Abuse |
|
|
|
| 16 Feb 2015 04:24 PM |
Problem:
local Player = game.Players.LocalPlayer local Char = Player.Character local Frame = script.Parent local Next = Frame.Next local Previous = Frame.Previous local Type = Frame.Type
local ClothingTable = {"Villager", "Wizard"}
Next.MouseButton1Down:connect(function() CurrentType = CurrentType % #ClothingTable Type.Text = ClothingTable[ CurrentType ] end)
Previous.MouseButton1Down:connect(function() CurrentType = ( CurrentType - 1 >= 1 and CurrentType - 1 or #ClothingTable ) Type.Text = ClothingTable[ CurrentType ] end)
When I click Previous
>17:25:13.915 - Players.Player.PlayerGui.Customization.Outline.Clothing.Loc:16: attempt to perform arithmetic on global 'CurrentType' (a nil value) 17:25:13.917 - Stack Begin 17:25:13.917 - Script 'Players.Player.PlayerGui.Customization.Outline.Clothing.Loc', Line 16 17:25:13.918 - Stack End
When I click Next
>17:25:30.827 - Players.Player.PlayerGui.Customization.Outline.Clothing.Loc:11: attempt to perform arithmetic on global 'CurrentType' (a nil value) 17:25:30.829 - Stack Begin 17:25:30.829 - Script 'Players.Player.PlayerGui.Customization.Outline.Clothing.Loc', Line 11 17:25:30.830 - Stack End
"I like to program." - Bosswalrus |
|
|
| Report Abuse |
|
|
|
| 16 Feb 2015 04:28 PM |
Below the line
local ClothingTable = {"Villager", "Wizard"}
type
local CurrentType = 1
It should look this this:
local ClothingTable = {"Villager", "Wizard"} local CurrentType = 1 |
|
|
| Report Abuse |
|
|
|
| 16 Feb 2015 04:29 PM |
Also, change
Next.MouseButton1Down:connect(function() CurrentType = CurrentType % #ClothingTable Type.Text = ClothingTable[ CurrentType ] end)
to
Next.MouseButton1Down:connect(function() CurrentType = CurrentType % #ClothingTable + 1 Type.Text = ClothingTable[ CurrentType ] end) |
|
|
| Report Abuse |
|
|
|
| 16 Feb 2015 04:30 PM |
>17:30:32.106 - String expected 17:30:32.107 - Script 'Players.Player.PlayerGui.Customization.Outline.Clothing.Loc', Line 14 17:30:32.107 - Stack End
local Player = game.Players.LocalPlayer local Char = Player.Character local Frame = script.Parent local Next = Frame.Next local Previous = Frame.Previous local Type = Frame.Type
local ClothingTable = {"Villager", "Wizard"}
local CurrentType = 1
Next.MouseButton1Down:connect(function() CurrentType = CurrentType % #ClothingTable Type.Text = ClothingTable[ CurrentType ] end)
Previous.MouseButton1Down:connect(function() CurrentType = ( CurrentType - 1 >= 1 and CurrentType - 1 or #ClothingTable ) Type.Text = ClothingTable[ CurrentType ] end)
"I like to program." - Bosswalrus |
|
|
| Report Abuse |
|
|
|
| 16 Feb 2015 04:30 PM |
It's making CurrentType the Type's Text. Current Type is a number value. How would we make it Villager, then Wizard? Then if I press Previous, Villager.
"I like to program." - Bosswalrus |
|
|
| Report Abuse |
|
|
| |
|
|
| 16 Feb 2015 04:33 PM |
Thank you, now to re create this script in a way I can understand it better.
"I like to program." - Bosswalrus |
|
|
| Report Abuse |
|
|
|
| 16 Feb 2015 04:35 PM |
Also, two quick questions:
In:
Next.MouseButton1Down:connect(function() CurrentType = CurrentType % #ClothingTable + 1 Type.Text = ClothingTable[ CurrentType ] end)
CurrentType = CurrentType % #ClothingTable + 1
What does the % do?
What does #ClothingTable mean, is it for every item in ClothingTable?
"I like to program." - Bosswalrus |
|
|
| Report Abuse |
|
|
|
| 16 Feb 2015 04:36 PM |
| If you're confused about anything, or need a brief explanation, tell me. |
|
|
| Report Abuse |
|
|
|
| 16 Feb 2015 04:38 PM |
I am, read my previous post.
"I like to program." - Bosswalrus |
|
|
| Report Abuse |
|
|
|
| 16 Feb 2015 04:43 PM |
Also could you explain this line?
CurrentType = (CurrentType - 1 >= 1 and CurrentType -1 or #ClothingTable)
"I like to program." - Bosswalrus |
|
|
| Report Abuse |
|
|
|
| 16 Feb 2015 04:49 PM |
[ What does #ClothingTable mean, is it for every item in ClothingTable? ]
Yes, you have it correct. The hash tag in Lua gives you the max amount of "items" of an Instance. You can determine how many strokes are in a word by doing the following:
In string format:
local Message = 'Hello' print(#Message)--> 5
Theres 5 strokes in the word "Hello".
In table format: local Table = {1,2,3,4,5,6,7,8,9,10} print(#Table)--> 10
Theres 10 Index's in the Table.
[ What does the % do? ]
The "%" symbol is called a Modulus in coding. Modulus gives us the remainder of 2 numbers. For example:
17 % 3 = 2.
17 / 3 = 5 (about)
5 can go into 17 3 times, with a remainder of 2 (3*5 = 15. 17-15 = 2).
I used % in that typical occasion because once the "CurrentType" reaches the max amount of indexes in the table, it will revert back to 1.
Lets say CurrentType = 2, and theres 2 total indexes inside the Table, if i add 1 more to CurrentType, it will revert back to 1 because 3 % 2 = 1.
|
|
|
| Report Abuse |
|
|
|
| 16 Feb 2015 04:55 PM |
Thank you, could you explain: CurrentType = (CurrentType - 1 >= 1 and CurrentType -1 or #ClothingTable)
"I like to program." - Bosswalrus |
|
|
| Report Abuse |
|
|
|
| 16 Feb 2015 04:56 PM |
[ The line ]::
CurrentType = (CurrentType - 1 >= 1 and CurrentType -1 or #ClothingTable)
I just recently learned this myself, but it works as an "if" "else" statement, but shortened, and no "if" or "else".
Let me abbreviate the entire line in a "if", "else" statement.
local CurrentType = 2 local ClothingTable = { "Villager", "Wizard" }
if ( CurrentType -1 ) >= 1 then -- If CurrentType - 1 is Greater than or Equal to 1 then CurrentType = CurrentType - 1 --CurrentType equals to CurrentType - 1 --This tells us that we can go down by 1 if the CurrentType variable is bigger than or equal to 1, and sets CurrentType to CurrentType - 1. else -- If CurrentType - 1 is not Greater than or Equal to 1 then CurrentType = #ClothingTable --CurentType equals to the number of indexes inside of ClothingTable. --This tells us that we can't go down by 1 anymore, so the variable of CurrentType reverts back to the number of Indexes inside ClothingTable. end |
|
|
| Report Abuse |
|
|
|
| 16 Feb 2015 05:01 PM |
That's amazing, thanks.
"I like to program." - Bosswalrus |
|
|
| Report Abuse |
|
|