i would like to know how i could cut and mix strings, im making a player fusion script for my game, but i dont know how i can make their name be togheter, like, if player 1 name is LordNoob and player 2 name is Keyboard then it would mix their names to one like Lordoard or KeyNoob something like that.
Ive searching a few things on the roblox wiki but i didnt found nothing, i saw string patterns but i dont know if it would help me.
If anyone could tell me what i could do it would be a cool help. thank you.
I've tried making a function for you which works okay, having the flaws that Paul mentioned
function mixStrings(string1,string2)
return string.upper(string.sub(string1,1,1)) .. string.lower( string.sub( string.sub(string1,1,math.floor(string.len(string1)/2)) ,2,string.len(string.sub(string1,1,math.floor(string.len(string1)/2)))) .. string.sub(string2,math.ceil(string.len(string2)/2),string.len(string2)) )
end
print(mixStrings("Keyboard","Calculator"))
print(mixStrings("Narwhal","Shark"))
print(mixStrings("America","Europe"))
print(mixStrings("Spoon","Fork"))
Running the above script resulted in the following when I tested it:
Keybulator
Narark
Amerope
Spork
(Btw the function will always make a string with a capitalized first letter and the rest will be lowercase, so it probably won't be useful if you're aiming to make something like KeyNoob)
Related
I'm attempting to mod a game I've been playing recently, and I've encountered an error when writing some code that adds a new mechanic. The problem itself isn't very complicated, but I can't seem to figure out what the solution is in this context. I'm pretty new to coding, especially with lua, so I apologize if the solution is really obvious. I've looked around for some answers, but again, nothing I can find seems to help me in this specific context. The game I'm trying to mod is called Project Zomboid, if that helps.
When attempting to start the game with the mod enabled, the error "Object tried to call nil in isBloodthirsty" pops up. Here's the snippet of code that's causing the error:
local function isBloodthirsty(player)
if player:getDescriptor():getTrait() ~= "bloodthirsty" then
return false else
return true
end
end
Ignoring how poorly written it is, the code was supposed to check if the player had a certain trait, and if so, then set the value isBloodthirsty to true. I think the error is caused by lua not recognizing the value "bloodthirsty", but I'm not sure what I should put instead. If anybody has an idea of what I'm doing wrong, I'd greatly appreciate some help. If it's helpful, I can post the rest of the code.
Thanks to all the great help from the stack overflow community, I managed to figure out what my problem was. The code I had written wasn't working because lua didn't recognize "bloodthirsty" as a valid trait string. My solution was to mix up the code a bit and frame the trait as a profession instead (a profession is kind of like a collection of traits within the game). The following code worked:
local function bloodthirstyStart(player)
if player:getDescriptor():getProfession() ~= "bloodthirsty" then
return
end
I am new to roblox scripting, and I am working on a game. I am trying to make an exploration game with multiple planets. I want the colors on the surfaces of the planets to vary, but I also wish to use smooth terrain, as it is easier to use and looks nice. from reading a bit online, i have figured out i need to use "GetMaterialColor" or "SetMaterialColor". however, "SetMaterialColor", the one i needed specifically, requires two bits of information- the material and the color.
The issue comes from the "Material" part of this, as I have no idea how to make the script recognize what material I want to change. i tried multiple things, including but not limited to:
(grass, #,#,#)
(grass) (#,#,#)
("Grass"), (#,#,#)
("Grass", #,#,#)
or even just (#,#,#), without trying to get a specific material at all
so yeah, I need some help
here is the code:
local function onTouch(hit)
game.Workspace.Terrain:SetMaterialColor
end
script.Parent.Touched:connect(onTouch)
(there should be stuff after SetMaterialColor, that is what i need help with)
If you read the documentation on Terrain:SetMaterialColor(), you'll see that the first argument is a Material type, which is an Enum. So the method expects an Enum (or number to be more accurate), not a string denoting the material.
At the same time the second argument is a Color3, so (#,#,#) isn't apt, using it with the constructor Color3.fromRGB(#,#,#) is. If you are ever confused about what a method returns or expects, try referring to its documentation on https://developer.roblox.com/.
Here's an example of correct usage:
workspace.Terrain:SetMaterialColor(Enum.Material.Grass, Color3.fromRGB(123,123,123))
And ofcourse, Event:Connect() instead of Event:connect()
Hey guys I recently started working with mutagen and I'm facing a very annoying problem.
Let´s say I´m trying to print the title of a wma file with mutagen:
from mutagen.asf import ASF
song=r"C:\Users\j2the\Music\The One and Only\Rammstein\Made In Germany\03 Keine Lust.wma"
song_wma=ASF(song)
print(song_wma["Title"])
The code may work fine, but when printing the title of the wma file, python always adds the extension [ASFUnicodeAttribute...] to the actual filename:
[ASFUnicodeAttribute('Keine Lust')]
Is there any way to have the code return only the actual title of the song?
Thanks in advance for your help!
Ok I eventually figured out the solution myself. It's actually very simple. All you have to do is iterate over the title tag and voilà: You´re left with only the title of the song:
for e in song_wma["Title"]:
print(e)
Outcome:
Keine Lust
And by the way, if anybody is loooking for an easy tagging module for mp3, wma, flac files etc., I would recommend the tinytag module, which is much less complicated to work with than the mutagen module. Just my personal opinion though.
How do I add use the bell character with Xterm.js? I see a couple of entries in the sources 'options' defaults, but dont get anything whether i send it from the shell or write it directly to the terminal, even with those set to true. I tried overloading the term.bell function with one containing a window.navigator.vibrate, and that works if I call it directly, but doesnt fire in response to a bell character.
Ok. So testing determined nothing is blocking the bell character ("\x07" or "\u0007") from getting through to xterm.js. It just doesnt respond, even if you enable the flags in the options. The code in the source looks like it should work, but something internal is not connected. Since I am avoiding actual changes to the source to make upgrades to xterm.js straightforward and out of the box, I worked a little magic. Here's a hack to get the bell character working:
Make a function that fires on the "message" event from your websocket. In it, check for a match for BEL. Then have it do your voodoo if it detects it. Something like:
sock.addEventListener('message',function(v){ if(v.match(/\x07/)){ /*voodoo here*/ } });
Where v is event, \x07 is BEL, and voodoo is code or an invocation to blip the screen white briefly, make a chirp, vibrate if your getting around on "mobile", or open a portal to the single-sock dimension.
Annoyingly, now I need to look up more ansi codes and find a pattern, as some end in a BEL character. So this will work by itself, but will be set off by some codes not intended to act as BEL, because they contain that character. More on this later....
FYI, not sure if this works with term.attach(). I have my own thing that does some preprocessing anyway, so basically all I had to do was splice in the if/match, but cut that out, the above code is the minimal cut-paste version.
Hope this helps someone else. Bug out.
I ran into some problems with my code and I don't know how to fix it. So my problem:
On a View of my application, there is a filepath displayed like this:
/resume/attachment/12/yaml_error_complete.yml
But I only want the filename as Output, means:
yaml_error_complete.yml
How can i achieve this? I tried with several options like string.slice! etc, but it doesn't work, since the number after "attachment" is increased by 1 for every single upload. At beginning I thought about to simply remove 2 chars, don't matter what they are. But then i ran into another problem that happens when the 100 file is uploaded. In this case i would have to remove 3 chars instead of 2, and i'm again at the beginning of my problem.
May someone of you can help me?
Thanks a lot!
I assume that you need to retrieve the file of a path.
for ex if your file name is "/resume/attachment/12/yaml_error_complete.yml"
Then try this one
"/resume/attachment/12/yaml_error_complete.yml".split('/').last
If I understand your question right, then, maybe it should help you:
a = "/resume/attachment/12/yaml_error_complete.yml"
a.split('/').last
#=> "yaml_error_complete.yml"
In addition to the sulution with split('/') you could do the following
File.basename("/resume/attachment/12/yaml_error_complete.yml")