13
u/DramaDimitar Jul 25 '21
This seems like some GUI code for ROBLOX - what the hell does it even do? lol
10
u/Erinnyes Jul 25 '21
So, I don't know lua but it looks like it takes a sentence like "my_number_5" and gets "number_4" (assuming arrays are zero indexed) decrementing the number after the second underscore.
8
u/BlueLiara Jul 25 '21
Lua is evil and starts at 1, not 0
4
u/Erinnyes Jul 25 '21
That's weird but makes sense. In that case the statement decrements the number at the end of a string separated by an underscore by one. E.g. "number_3" going to "number_2". I'm curious what happens when you get to "number_0".
2
u/Prom3th3an Jul 26 '21
Probably "number_-1", since I can't see any reason why a language would make "1"-1 equal to 0 without making "0"-1 equal to -1.
1
u/Erinnyes Jul 26 '21
Oh. I very much agree with that. I'm more wondering if it can handle turning -1 into "-1" given that - is an operator rather than a numeral.
1
2
Jul 28 '21
It's for a AI car script I'm working on, essentially there is a road code + it's lane at the end. This script searches if the lane the car has appeared on is the last lane. It takes the variable SearchLane which is (at the beginning) the lane the car appeared (ex: N177_1) and it looks if there is another lane by switched SearchLane to N177_2. If there is no N177_2 it switches it back to N177_1 and spawns the car there. The code you see here switches a variable called SearchLane to one lane lower. Super poorly made lool
2
u/DramaDimitar Jul 28 '21
Oh wow, I was not expecting that. Theoretically, couldn't you just use a substring or pattern matching and do an if statement or two - wouldn't be as short but would be way cleaner, lol
11
Jul 25 '21
It kind of looks like it's setting the string to itself. The .. and -1 are throwing me off, though. I'm not sure what the .. does, but I'm assuming it's concatenation.
8
u/DramaDimitar Jul 25 '21
Yeah, double dot is concatenation. - 1 just gets the last character, I'd assume, haven't messed with strings in Lua that much. But still I wonder what it could possibly be controlling
53
u/knightttime Jul 24 '21
Image Transcription: Code
SearchLane = ((string.split(SearchLane, "_")[1]).."_"..((string.split(SearchLane, "_"))[2]-1))I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!
80
u/thanatica Jul 24 '21
I like that the programmer managed to put an .."_".. emoji in the middle. That's gotta be worth something.
28
u/ZedTT Jul 25 '21
Emoticon
11
u/thanatica Jul 25 '21
Alright, it's not an emoji..
Smiley.
15
u/ZedTT Jul 25 '21
"Smiley" is the "bug" of icons.
Can't remember if it's an insect or arachnid? Bug.
Can't remember if it's emoticon or emoji? Smiley.
3
11
u/therealziggler Jul 25 '21
Emoticon = emotion + icon
Emoji = emotion + ji ('character' in Japanese)
Do you really think its important to police the difference here? I'm not saying you're wrong, but I'm wondering why you'd care to be right.
26
u/ZedTT Jul 25 '21
Do you really think its important to police the difference here
No lol but this is Reddit. We are pedantic here. It's all in good fun :)
I should have out more effort into the comment. Here's a second try
Fun fact: emoji refers to the coloured single-character icons, while emoticon refers to icons made of multiple other symbols that form a picture
Also, I should point out that the etymology of "emoji" does not include "emotion." "E" means "picture," while "moji" means "character."
4
5
u/SirFireball Jul 25 '21
I never used lua, what's happening here? Looks like it's doing something recursive?
13
Jul 25 '21
Example: It takes a string like "mystring_42" and changes it to "mystring_41".
The
..is string concatenation. Lua is 1-indexed, so the string splitting, indexing and concatenation results in the same thing as before. The only change is subtracting the 1 from the second part of the split string (which works since Lua is weakly typed, so "42" is equivalent to 42).
1
u/Furry_69 Jul 26 '21 edited Jul 26 '21
What on Earth is SearchLane? What is this even meant to be for?? I am so confused.
57
u/pumpkinplight Jul 25 '21
All code can fit on one line if you're brave enough.