Just a question, I don’t have a script.
How would I add to a string? For example, if I had the string
“I love”
how could I add words to it like “tacos” or “sandwiches”?
Just a question, I don’t have a script.
How would I add to a string? For example, if I had the string
“I love”
how could I add words to it like “tacos” or “sandwiches”?
string = “I love”. .“tacos”
two periods add to it
use ". . " this is the symbol used to add strings. If I have “Tacos” and “Hotdogs” and then I do:
“Tacos” . . “Hotdogs” I will be getting as a result “TacosHotdogs”
Its doing the same thing why cant we add only 2 periods
That’s… not what I meant.
]9009099090]
Really annoying, didnt even knew this was a feauture
What did you mean then? What are you trying to do?
You know those keypad doors people made back then? Like when they click a number on the keypad, it updates a textlabel with what they pressed.
So if I pressed “8068”, it would go
8
80
806
8068
for that you use “UserInputService”
This code wil run in the Client
local userInputService = game:GetService("UserInputService");
userInputService.InputBegan:Connect(function(input)
if(input.KeyCode == Enum.KeyCode.KeypadEight) then
print("Keypad 8 was pressed :D")
end
end);
Now remember that to add to a string you will use: string .. string2
Search Enum KeyCode to see all the keycodes available, hope this helps : D
No-
…Okay, nevermind. I honestly didn’t know what I expected asking that question.
what do you need then? There is the code to detect the input the only thing you need to do is to reference the text label and set it with the string that adds
I think like it works like how you type. Type 0 then you type 3 it shows as 03?
The people in the the replies are correct
if you want to add 2 strings together into one you need to put “…”
string = "Cool".."Man" -- "CoolMan"
--Or
string1 = "foo"
string2 = "bar"
newstring = string1..string2 -- "foobar"
Maybe I’m not understanding did you want to take 2 numbers that are strings and add them?
use the tonumber function
number = tonumber("5") + tonumber("7") -- 12
I suggest making a table and everytime a new number is entered, enter that number into a table then use table.concat
to get the entire code.
local t = {}
local numbers = {1, 2, 3, 4}
for i = 1, #numbers do
table.insert(t, numbers[i])
end
print(table.concat(t))
The above example loops through the numbers table and inserts each number then prints 1234
.
Also, concatenating using ..
works just fine, why not just save the previous string and add to it?
local Numbers = {1, 2, 3}
local PreviousString = Numbers[1] .. Numbers[2]
local NewString = PreviousString .. Numbers[3]
print(PreviousString)
print(NewString)
Above prints 12
then 123
.
I know that ..
works to concatenate strings but I’m more familiar with Python where we can just put .append() to the end of something and it will do just that.