ProtectedString: Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>Mattchewy
Nasty code you had there...
m Text replacement - "<SyntaxHighlight code="lua">" to "<syntaxhighlight lang="lua">"
 
(14 intermediate revisions by 6 users not shown)
Line 1: Line 1:
=== Introduction ===
'''WARNING: The following tutorial will not work anymore because the String property was locked.'''
----
A [[ProtectedString]] is a data type that imitates the behavior of a [[String]] while still being very differrent. This type of [[String]] is neither readable or writable from [[Script]]s.  Here, I will use the [[Script]]'s [[Source (Property)|Source]] property to demonstrate what would happen if you were to attempt to manipulate a [[ProtectedString]].


<pre>
== Introduction ==
print( Workspace.Script.Source )</pre>
A {{type|ProtectedString}} is a data type that imitates the behavior of a {{type|string}} while still being very differrent. This type of {{type|string}} is neither readable or writable from [[Script]]s. Here, I will use the [[Script]]'s [[Source (Property)|Source]] property to demonstrate what would happen if you were to attempt to manipulate a {{type|ProtectedString}}.


This would call an error saying that ''Source'' is not a valid member of ''Script''. This is because the script you are using doesn't recognize ''Script.Source''.  It won't recognize any other [[ProtectedString]] value either.
<syntaxhighlight lang="lua">
print( Workspace.Script.Source )</syntaxhighlight>


There is no way to create a [[ProtectedString]] value.
This would print an error saying that ''Source'' is not a valid member of ''Script''.  This is because the script you are using doesn't recognize ''Script.Source''.  It won't recognize any other {{type|ProtectedString}} value either.


There is no way to create a {{type|ProtectedString}} value.






=== Getting around ''Script.Source'' ===
----


== Getting around ''Script.Source'' ==
This is a major obstacle that gets in the way of many scripters all around Roblox.  It's the problem of setting a [[Script]]'s [[Source (Property)|Source]].  Many scripters will try to set ''Script.Source'' the conventional way:
This is a major obstacle that gets in the way of many scripters all around Roblox.  It's the problem of setting a [[Script]]'s [[Source (Property)|Source]].  Many scripters will try to set ''Script.Source'' the conventional way:


<pre>
<syntaxhighlight lang="lua">
Workspace.Script.Source = [[print("Hello, World!")]]</pre>
Workspace.Script.Source = [[print("Hello, World!")]]</syntaxhighlight>


Unfortunately, this does not work.  There is only one way to set the Source property and it is as follows:
Unfortunately, this does not work.  One way to get around this is to add a [[StringValue]] to simulate the Source of the script.


<pre>
<pre>
Line 27: Line 26:


Workspace
Workspace
-Script   [Disabled = true]
-Script
--SourceCode  [className = StringValue]</pre>
--SourceCode  [className = StringValue]</pre>


Line 34: Line 33:
<pre>
<pre>
script.SourceCode.Changed:connect(function()
script.SourceCode.Changed:connect(function()
assert( loadstring( script.SourceCode.Value ) )()
loadstring( script.SourceCode.Value )()
end</pre>
end)</pre>


Your script's source:
Your script's source:

Latest revision as of 05:25, 27 April 2023

WARNING: The following tutorial will not work anymore because the String property was locked.

Introduction

A ProtectedString is a data type that imitates the behavior of a string while still being very differrent. This type of string is neither readable or writable from Scripts. Here, I will use the Script's Source property to demonstrate what would happen if you were to attempt to manipulate a ProtectedString.

print( Workspace.Script.Source )

This would print an error saying that Source is not a valid member of Script. This is because the script you are using doesn't recognize Script.Source. It won't recognize any other ProtectedString value either.

There is no way to create a ProtectedString value.



Getting around Script.Source

This is a major obstacle that gets in the way of many scripters all around Roblox. It's the problem of setting a Script's Source. Many scripters will try to set Script.Source the conventional way:

Workspace.Script.Source = [[print("Hello, World!")]]

Unfortunately, this does not work. One way to get around this is to add a StringValue to simulate the Source of the script.

HIERARCHY:

Workspace
-Script
--SourceCode   [className = StringValue]

Workspace.Script's source:

script.SourceCode.Changed:connect(function()
loadstring( script.SourceCode.Value )()
end)

Your script's source:

Workspace.Script.SourceCode.Value = [[print("Hello, World!")]]

--> Hello, World!