Replace all function

Ctrl + Shift + F finds all lines of a script with the specified piece of text. Why not have it replace as well with a specified piece of code? This would make things MUCH easier if you had a few in errors in many scripts.

If you have a bunch of scripts that need to do the same thing then you should be requiring a module that returns a function to do that thing.

I know, but a friend of mine and his inefficiencies… What happened was he had the Source ModuleScript, but for some reason to copy around 3k copies. So each script, approx. 3.5k, were requiring a clone. I said to make it require from the Source. So he had to change that one line of code in 3.5k scripts manually. Sounds fun, doesn’t it?

“Why not have it replace as well with a specified piece of code?”

There are two possibilities here:

  1. The piece of code you’re replacing is longish.
    If that’s the case it should be in a module containing that common logic, not in a whole bunch of different scripts.

  2. The code isn’t very long, just a couple of tokens
    This would have disastrous consequences used with most replacement strings, as you’d more than likely end up replacing a bunch of things that you did not mean to, creating possibly subtle bugs elsewhere in your project where you don’t notice them until later after wasting a whole bunch of time debugging them.

“I said to make it require from the Source. So he had to change that one line of code in 3.5k scripts manually.”

So then… we don’t want to add such a feature lest we encourage people to continue doing terrible things like that.

[quote] “I said to make it require from the Source. So he had to change that one line of code in 3.5k scripts manually.”

So then… we don’t want to add such a feature lest we encourage people to continue doing terrible things like that. [/quote]

I fail to see how that would encourage them.

[quote] “Why not have it replace as well with a specified piece of code?”

There are two possibilities here:

  1. The piece of code you’re replacing is longish.
    If that’s the case it should be in a module containing that common logic, not in a whole bunch of different scripts.

  2. The code isn’t very long, just a couple of tokens
    This would have disastrous consequences used with most replacement strings, as you’d more than likely end up replacing a bunch of things that you did not mean to, creating possibly subtle bugs elsewhere in your project where you don’t notice them until later after wasting a whole bunch of time debugging them. [/quote]

Understand this was one line of the code, the EXACT SAME line of code 3.5k times, in 3.5 different scripts.

[quote] “I said to make it require from the Source. So he had to change that one line of code in 3.5k scripts manually.”

So then… we don’t want to add such a feature lest we encourage people to continue doing terrible things like that. [/quote]

I fail to see how that would encourage them.[/quote]

Because it makes it more possible. If you really want this you can make a plugin for it.

[quote] [quote=“Stravant” post=60697]“I said to make it require from the Source. So he had to change that one line of code in 3.5k scripts manually.”

So then… we don’t want to add such a feature lest we encourage people to continue doing terrible things like that. [/quote]

I fail to see how that would encourage them.[/quote]

Because it makes it more possible. If you really want this you can make a plugin for it.[/quote]

Tell me how and I’ll do it. Also, makes it more possible? Makes what more possible.

[quote] [quote=“CeaselessSoul” post=60708][quote=“Stravant” post=60697]“I said to make it require from the Source. So he had to change that one line of code in 3.5k scripts manually.”

So then… we don’t want to add such a feature lest we encourage people to continue doing terrible things like that. [/quote]

I fail to see how that would encourage them.[/quote]

Because it makes it more possible. If you really want this you can make a plugin for it.[/quote]

Tell me how and I’ll do it. Also, makes it more possible? Makes what more possible.[/quote]

It makes it more possible to commit this crime against good coding practice. Currently there’s no easy way to replace all so people are careful to write good code. If roblox starts introducing ways to salvage bad code then people will write more bad code since there aren’t consequences anymore.

Think of it like eating cookies, which are bad for your health. If you have to go bake your own cookies then you’ll only eat them rarely and you’ll think about the health consequences before putting all that effort into making them, but if someone sells you packs of pre-baked cookies then you’ll eat them all the time since they’re right there and become unhealthy as a result.

As for the plugin, here’s a basic rundown of how I’d do it

1- make plugin 2- open replace all menu when mouse presses ctrl+shift+h 3- have the player enter the find and replace texts and click replace all 4- look for every script in the game 5- script.Source=script.Source:gsub(findText, replaceText)

“Tell me how and I’ll do it.”

local modules = getAllModulesInGame()
for _, module in pairs(modules) do
module.Source = module.Source:gsub([=[ find ]=], [=[ replaceWith ]=])
end

But, the real problem in that case is why there are 3.5K scripts in the first place. The absolute most code a place should have in it if well constructed is ~100 modules and ~50 scripts.

[quote] “Tell me how and I’ll do it.”

local modules = getAllModulesInGame()
for _, module in pairs(modules) do
module.Source = module.Source:gsub([=[ find ]=], [=[ replaceWith ]=])
end

But, the real problem in that case is why there are 3.5K scripts in the first place. The absolute most code a place should have in it if well constructed is ~100 modules and ~50 scripts. [/quote]

Why do you think I wanted him to change it?

Not to possibly sound dumb… but have you ever heard of CTRL+H?

Edit: Read down the thread and you seem to mean in many different scripts, whereas the OP says a single script. Edit OP maybe?

[quote] Not to possibly sound dumb… but have you ever heard of CTRL+H?

Edit: Read down the thread and you seem to mean in many different scripts, whereas the OP says a single script. Edit OP maybe? [/quote]

I think that said it all.

[quote] My question:
What kind of game needs three and a half THOUSAND SCRIPTS!? Did he just keep copying script into bricks instead of using one script, one for loop, and one piece of code for all of them!? My goodness!! [/quote]

He had 3.5k of the same script (ModuleScript), he apparently forgot you only need one and can place it anywhere to be called. So he had 3.5k scripts because this is an RPG, he put each ModScr inside of just each of the scripts to be called like so: require(script:WaitForChild(“Library”)). Naturally, I told him, THAT’S INEFFICIENT JUST BY A LITTLE BIT. By the way, I’m not exaggerating.

[quote] My question:
What kind of game needs three and a half THOUSAND SCRIPTS!? Did he just keep copying script into bricks instead of using one script, one for loop, and one piece of code for all of them!? My goodness!! [/quote]

He had 3.5k of the same script (ModuleScript), he apparently forgot you only need one and can place it anywhere to be called. So he had 3.5k scripts because this is an RPG, he put each ModScr inside of just each of the scripts to be called like so: require(script:WaitForChild(“Library”)). Naturally, I told him, THAT’S INEFFICIENT JUST BY A LITTLE BIT. By the way, I’m not exaggerating.[/quote]

Wait… 3.5k MODULESCRIPTS

[quote] [quote=“CodeTheorem” post=60878]My question:
What kind of game needs three and a half THOUSAND SCRIPTS!? Did he just keep copying script into bricks instead of using one script, one for loop, and one piece of code for all of them!? My goodness!! [/quote]

He had 3.5k of the same script (ModuleScript), he apparently forgot you only need one and can place it anywhere to be called. So he had 3.5k scripts because this is an RPG, he put each ModScr inside of just each of the scripts to be called like so: require(script:WaitForChild(“Library”)). Naturally, I told him, THAT’S INEFFICIENT JUST BY A LITTLE BIT. By the way, I’m not exaggerating.[/quote]

Wait… 3.5k MODULESCRIPTS

LOL FOR GOOD GOD AND ALL THAT IS HOLY! I love that gif, and yes, both, scripts and ModuleScripts…