What means PCALL, WARN, 2 DOTS in a script?

Welcome DevForum!
I need your help very fast.

  1. What do you want to achieve? Keep it simple and clear!
    I want from someone a clear answer of the next listed scripting things I don’t understand. Included, if possible an example.

  2. What is the issue? Include screenshots / videos if possible!
    I have some scripting terms that I don’t understand.

  • Pcall
  • Warn
  • In some scripts they having this kind of local variable:
local firstWord, secondWord = [Variable] 
  • When u are using (“Hello”) and when u are using “Hello”?
  • And the last thing is this`, when you use 2 dots and not 1?:
local playerUserId = "Player_"..player.UserId
  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I am now 1 day long busy with this but i can’t find the correct answer.
  • DevFroum
  • Youtube
  • Roblox API

Regards,
JailBreak2007_1

1 Like

Pcall - I don’t know
Warn - Equals Print but used to warn a error(or something like that) on output.
2 Dots - Example print("1 + 1 = " 1+1) - this doen’t work,but if u made print("1 + 1 = " … 1+1) in output will appear: 1 + 1 = 2
…idk how to say… its used to print(or other thing, like variable values) variables and more things in the same print.

2 Likes

The function of Warn is clear, thanks!

2 Likes

The .. is concatination, it is used to associate strings with a variable that can change, for example you have 150 money, and the Money value is in the player.

To show it in a GUI or in a TextFeild with other text you would do: text =
"You have ".. game.Players.LocalPlayer.Money.Value.. " Money." and it would appear in the textfield as
You have 150 Money

warn() is print(). but instead prints it in orange/yellow text.

2 Likes

pcall - Used to wrap a block of code to prevent errors from going to the output. Returns if the block of code executed successfully or not as a bool (ex. true if successful and false if not) and an error message if it wasn’t successful

Usage:

local success, errormessage = pcall(function()
    print("Working")
end)

if (success) then
    --if it was successful and no errors occurred
else
    --if it wasn't successful and errors occurred
    warn(errormessage) --have to call the errormessage variable to see why the pcall or block of code failed
end
3 Likes

Means this you can use 2 names for 1 local variable?

1 Like

Yep, as long as you’re setting those 2 variables.
Example:

local one, two = 1, 2

You can even do more.

Can’t do one variable for two things, a table or dictionary would be better for that.

1 Like

pcall is used to prevent from errors stopping the whole script. (I don’t really know how to explain)

Heres an example of a pcall being used:

local success, result = pcall(function()
return datastore:GetAsync(key)
end)

if success then
print(result) -- prints the data
else
warn(result) -- warns the error
end
1 Like

Thanks for your answers! You all really helped me out.

4 Likes

No problem. Glad we helped you.

1 Like

@MixedConscience but here aren’t 2 variables?! or is return the second variable?

When you’re using return in a pcall, it would return the value you returned to the second variable if the pcall was successful. If it wasn’t successful it wouldn’t return the value, instead would make that variable the error message as to why it failed.

2 Likes

So that means that the Return from the Pcall is directly the new value of the second listed variable?

Yes. Remember, if it was successful.

1 Like

And when the Pcall isn’t succesfull the error message will be shown up?

PCALL

Short for protected call, pcall is a way to make sure a web request doesn’t fail

Warn()

This is just like print() but the text appears as yellow instead of white. You might also see error() which prints an error. I have never used warn or error.

Brackets for variables

Some developers make variables that have spaces in them, and you must surround these variables with brackets if they have spaces.

Parentheses around a string

This doesn’t really mean anything, it’s just a way some people like to organize their code.

The two dots

You use the two dots for concatenation, or for combining strings.

So for example this:

print(“He”…“llo”)

Will print “hello”

1 Like

You’re correct.
I’ll do some testing to show you.

Edit:


Here’s an example. This was successful so it returned the value to the second variable.

1 Like

Thanks! I am not an advanced scripter, if I am asking too much say it

but:

  • What does the if (a) checks?

It checks if it was successful.

Checks if it was successfully executed without errors @JailBreak2007_1
And no problem.