#How to append variables and strings to an object path

86 messages · Page 1 of 1 (latest)

lucid kettle
#

I'm currently trying to write a script that changes the UI I have from numbers to letters whenever I press L2 on a controller, but I can't seem to figure out just how to word this value. (I'm coming from normal Lua, so I'm not sure if this is part of the LuaU modifications.)

function PrepareControllerMoves()
    local CurCharacter = Player:GetAttribute("SelectedCharacter")
    local CurMoveset = ModeDisplay.Text
    local Moveset = SSs.Characters[CurCharacter]..Spawn.Main.CurMoveset
    AttemptingToUseMove = true
    
end
sick rampart
lucid kettle
#

Yeah

sick rampart
#

Do you have any place where you store the inputs?

#

e.g. a module, an attribute or some value instance

lucid kettle
#

I was just gonna replace the strings on the text labels with new strings 😅

sick rampart
#

That would work, just debugging that would be a tad odd

#

Anyways, if you know what button you're on and what button correlates to that then you can just do

Display.Text = KeyRequired

which is quite basic, but it's not much more than that

#

the diffucult part comes in when managing what keys correspond to what buttons

compact flume
#

Btw in case you still wanna know how to: workspace.path["instance name"].Whatever.Value

sick rampart
#

I would really advice you to just store those values somewhere

lucid kettle
#

because my main problem is getting to the Text inside of these image labels

sick rampart
#

is asgorespawn one of the potential CurCharacters?

compact flume
#

I'm in a car rn so can't really answer

lucid kettle
sour craterBOT
#

studio** You are now Level 1! **studio

sick rampart
#

Hang on, do all those have the text labels inside them?

lucid kettle
#

yes, they do

#

here let me send a quick example of what the ui looks like

sick rampart
#

if so then I would just do:

for _, ImageLabel in SSs.Characters[CurCharacters].Moves.Main.Fire do
  if ImageLabel.ClassName == "ImageLabel" then continue end
  ImageLabel.TextLabel.Text = --the right button
end
lucid kettle
sick rampart
#

that script is the easiest to use if you just have a table of the right keys

#
local ButtonTable = {
    ["ButtonName1"] = {
        ["Console"] = "L2",
        ["PC"] = "R"
    },
    ["ButtonName2"] = {
        ["Console"] = "L2",
        ["PC"] = "T"
    }--etc
}
lucid kettle
#

here let me try executing it myself to see if i've got this straight

#
for _, ImageLabel in SSs.Characters[CurCharacter]["Spawn"].Moves.Main[CurMoveset] do
    if ImageLabel.ClassName == "ImageLabel" then continue end
    ImageLabel.MoveNumber.Text = Button.Name
end
```correct?
#

as for the binds let me just

sick rampart
#

the main issue is that this will do all textlabels and will most likely set them all to 1 button

sick rampart
lucid kettle
#

yeah working on the table right now

#

i'll probably check back in after i'm done just to make sure

sick rampart
#

make sure you ping me when you do, for I will probably be dying in blender trying to get these lights to behave how I want them to

lucid kettle
#

@sick rampart kinda forgot how to operate tables considering this is the first time i've ever had to use one, how do i call these in the statement?

local Binds = {
        ["One"] = {
            ["XBox"] = "X",
            ["PC"] = "1",
            ["PlayStation"] = "□"
        },
        ["Two"] = {
            ["XBox"] = "Y",
            ["PC"] = "2",
            ["PlayStation"] = "△"
        },
        ["Three"] = {
            ["XBox"] = "A",
            ["PC"] = "3",
            ["PlayStation"] = "╳"
        },
        ["Four"] = {
            ["XBox"] = "B",
            ["PC"] = "4",
            ["PlayStation"] = "◯"
        },
        ["Five"] = {
            ["XBox"] = "LB",
            ["PC"] = "5",
            ["Playstation"] = "L1"
        },
        ["Six"] = {
            ["XBox"] = "RB",
            ["PC"] = "6",
            ["Playstation"] = "R1"
        },
        ["Seven"] = {
            ["XBox"] = "RT",
            ["PC"] = "7",
            ["Playstation"] = "R2"
        },
    }
    
    for _, ImageLabel in SSs.Characters[CurCharacter]["Spawn"].Moves.Main[CurMoveset] do
        if ImageLabel.ClassName == "ImageLabel" then continue end
        ImageLabel.MoveNumber.Text = Button.Name
    end
sour craterBOT
#

studio** You are now Level 2! **studio

lucid kettle
#

and also on that note, how do i check what type of controller a player is using 😅

sick rampart
#

I just noticed I made a mistake in the for loop

#

Then if ImageLabel… line’s == had to be a ~=

lucid kettle
#

ah

sick rampart
#

Now the image label’s name is in the table so we can set the textlabel’s text to

Binds[ImageLabel.Name][CurrentConsole]

#

One thing I must add is that I’m not sure how you’re planning on detecting xbox vs playstation. I know you can technically hook up a playstation controller but I never saw anything that can detect xbox vs playstation

#

Definitely as the inputs are just made for a gamepad, not xbox/ps specific

lucid kettle
#

there isn't?

#

i was kind of banking on that

sick rampart
#

Maybe some research can prove me wrong. But I don’t know of any way on how one would do that

lucid kettle
#

interesting

#

i've never seen a ButtonCross in Enum.Keycode

#

sure enough i just tried it and there's no autocomplete for it

#

but it definitely works

lucid kettle
#
if UIs:GetStringForKeyCode(Enum.KeyCode.ButtonA) == "ButtonCross" or UIs:GetStringForKeyCode(Enum.KeyCode.ButtonB) == "ButtonCircle" or UIs:GetStringForKeyCode(Enum.KeyCode.ButtonX) == "ButtonSquare" or UIs:GetStringForKeyCode(Enum.KeyCode.ButtonY) == "ButtonTriangle" then
        PlayStation = true
    end
``` there has to be an easier way to write this 😭
sick rampart
#

Are you sure? I checked the list of potential keycodes and it’s not present

#

Oh getsreuntforketckde hm

#

Oh wait

#

You’ve found something interesting

compact flume
#

You both are still over this 😭

sick rampart
lucid kettle
lucid kettle
#

i’m gonna go with my exorbitantly long if statement for now because i’ve been coding for three hours and it’s 6 am

sick rampart
#

I would argue that tables are one of the best things to learn early on in lua

lucid kettle
#

i suppose i’ll have to get cracking once again then

lucid kettle
sick rampart
#

Yes

lucid kettle
#

alright thanks a million

#

if something doesn’t work one of my Cur variables must’ve been wrong

#

so i should be good from here

sick rampart
#

You can just read the table as an example

#

Let’s say the user is on xbox and the code is working on button One

#

Then it goes to the Binds table, entry One (name of button) then goes to Xbox (name of console that your if else chain returns) and then returns a string with the correct button (blue)

lucid kettle
sour craterBOT
#

studio** You are now Level 3! **studio

lucid kettle
#

3 level ups in one forum

#

i see how you’re level 50 now

sick rampart
lucid kettle
#

someone’s dedicated

sick rampart
#

only 28k messages 🤷‍♂️

lucid kettle
#

@sick rampart are you still available 😭

marsh prawn
#

Im here, whats the issue @lucid kettle

sick rampart
lucid kettle
#

i figured it out, i was having an issue with ServerScriptService not finding a valid member

#

turns out the script i'm working in clones to a localscript in the player's backpack

#

which kinda screws with the whole thing i had going

#

of referencing serverscriptservice to fix stuff :/