-1

I need to add text that vs thinks it is code, im using richTextBox to hold that code because i dont know how to put it into code because vs thinks that is code but it is just a text that need to be send to a function later.

I tried something like that:

string something = @"_G.WS = {arg1};

local Humanoid = game:GetService("Players").LocalPlayer.Character.Humanoid;
Humanoid:GetPropertyChangedSignal("WalkSpeed"):Connect(function()
Humanoid.WalkSpeed = _G.WS;
end)
Humanoid.WalkSpeed = _G.WS;";

*all code here need to be just a multiline text

But visual studio thinks that is code but not text.

I tried use backslashes but this didnt helped too. richTextBoxes works but i need to change variables in that text but how can i change it if i cant do anything with text in texbox in code.

I need to do something like this:

function($@"_G.WS = {arg1};

local Humanoid = game:GetService("Players").LocalPlayer.Character.Humanoid;
Humanoid:GetPropertyChangedSignal("WalkSpeed"):Connect(function()
Humanoid.WalkSpeed = _G.WS;
end)
Humanoid.WalkSpeed = _G.WS;");

*all code here need to be just a multiline text

and it needs to be just a text not code, and $, @ wont help.

I dont know any another way to do this.

If its possible how can i do this?

ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86
Vasiliy
  • 1
  • 2
  • 1
    You have stated the problem of text box and VS for 5 times in the question. But its not clear what you are trying to do with `something` and which part of code gives you what issue – Chetan Jun 05 '18 at 11:31
  • 3
    "But visual studio thinks that is code" - no it doesn't think that. Why do you think that it thinks that? – bommelding Jun 05 '18 at 11:31
  • maybe do you want to escape characters in C# Refer https://msdn.microsoft.com/en-us/library/h21280bw.aspx?f=255&MSPPError=-2147217396 – vCillusion Jun 05 '18 at 11:33
  • I have command input (something like cmd) with some commands that executes code on another programming language. For example user typing say Something and program need to add code with variable on another programming lang to string and then send this string to function. Or without string, directly to function. – Vasiliy Jun 05 '18 at 11:35
  • 5
    You're not escaping the `"` in your code string. Replace the `"` with `""` (double quote) – EpicKip Jun 05 '18 at 11:48
  • @EpicKip Idk maybe im doing something wrong, but everything is same. – Vasiliy Jun 05 '18 at 11:52
  • @bommelding it does. Why then all text is red and gives compilation error – Vasiliy Jun 05 '18 at 11:53
  • The starting quote of `"Players"` ends the string literal. As EpicKip said, use doubled quotes inside the string: `""Players""` – Hans Kesting Jun 05 '18 at 11:55
  • I think its worked, ill test it, i was trying to take all string into double quotes, but now i understand, thanks – Vasiliy Jun 05 '18 at 11:56
  • @HansKesting Thanks for clearing that up :) [at Vasily] No problem. – EpicKip Jun 05 '18 at 12:03
  • Possible duplicate of [Can I escape a double quote in a verbatim string literal?](https://stackoverflow.com/questions/1928909/can-i-escape-a-double-quote-in-a-verbatim-string-literal) – EpicKip Jun 05 '18 at 12:03

1 Answers1

1

You can do this in two ways:

Add proper Quotations and escape sequences like:

string something = @"_G.WS = {arg1};
 local Humanoid = 
 game:GetService(""Players"").LocalPlayer.Character.Humanoid;
 Humanoid: GetPropertyChangedSignal(""WalkSpeed""):Connect(function()
 Humanoid.WalkSpeed = _G.WS;
            end)
 Humanoid.WalkSpeed = _G.WS; ";

Notice an extra quotation after the actual quotation you need?, it's needed by the interpreter to parse the string properly.

Else you can store it in Project settings which is provided by .NET readily :

enter image description here

Refernce Link: Settings in C#

Usage Example:

this.someting = Properties.Settings.Default.Something;

If i were you i would avoid avoid magic strings in code and keep it in a XML file or custom storage file.that way if you want to change the string then you don't have to worry about building and deploying your app again for just a string edit.

Dharani Kumar
  • 457
  • 2
  • 8