|
| 24 Feb 2012 07:25 PM |
This is one thing I'm really currently unsure of as a growing scripter right now. Equals and Quotations. I couldn't exactly find a wiki article with this information on it because I'm really not sure what the proper names they're referenced as are.
Though its simple, just the rulings for == and such, what are they? Anyone have a link for them? |
|
|
| Report Abuse |
|
|
|
| 24 Feb 2012 07:26 PM |
| Wooooooooooooooooow at my title. I don't know if I'm tired, or what. Is there a link to the rules, etc of these? |
|
|
| Report Abuse |
|
|
|
| 24 Feb 2012 07:28 PM |
If you want to change a items property then you use =.
e.g:
script.Parent.Transparency = 0
When you use 'if' statements you use ==.
e.g:
if script.Parent.Transparency == 0 then script.Parent.Transparency = 1 end
I also was confused about this when I first started to script. |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 24 Feb 2012 07:30 PM |
"When you use if statements you use ==."
You use == operator more times. You use it for more things than just if statements. |
|
|
| Report Abuse |
|
|
|
| 24 Feb 2012 08:46 PM |
So, I'm messing around with conditional statements and I'm trying to make it detect that the baseplate's Color is Bright green, though the output keeps telling me the problem is where the =='s are.
if script.Parent.Base.BrickColor == ("Bright green") then print("If statment 2 - Successful") else print("If statment 2 - Failed") end
20:44:40 - Workspace.ConditionalStatements:5: 'then' expected near '='
This is kind of where I'm getting stuck at again with basic things because I don't know the stipulations to them. Tried many different combinations, and really couldn't get it to be true. |
|
|
| Report Abuse |
|
|
|
| 24 Feb 2012 09:03 PM |
@CounterClockWork,
Correct. The "==" is used for if statements. If something==this then print("YAY!")
It's a check operator. Does "something" "equal" "this" then
and "=" is to set a value. |
|
|
| Report Abuse |
|
|
stravant
|
  |
 |
| Joined: 22 Oct 2007 |
| Total Posts: 2893 |
|
|
| 24 Feb 2012 09:05 PM |
Well, that's sort of a bad way to describe an if statement, since you don't even need to use == in a control structure, let alone an if statement. The following is perfectly valid code:
a = b == c Or more easily read: a = (b == c)
This will compare `b` and `c` and store the result of the comparison in the variable `a`. You see, anything which you can put in the condition of an if statement can be just as well stored in a variable, and vice-versa too.
When you write `==` it's really just another operator like `+` or `*`. It doesn't do anything special it works exactly like those other operators... only it returns the result of comparing it's two operands rather than adding or multiplying then. That value that it results in can either be `true` or `false`.
Now, `=` is NOT just another operator like `+` or `*`. It is reserved strictly for assigning a value to a variable or a property of an object. As a result you can't do something like `if a = b then`, it doesn't make any sense, because it's for assigning things, what would it even mean? "if a was assigned to b"? Well of course it was assigned... I just did assign it!
That's an important thing to know. Most things like `==` and even `and` and `or` are really just operators like + and -... but `=` is not, it has a special meaning. |
|
|
| Report Abuse |
|
|
|
| 24 Feb 2012 09:09 PM |
== Turns things into bool values (true false)
For example:
x = 1 j = x==2 print(j)
Since x is not = to 2, the statement x==2 is false, therefore the output will read:
--> false
This is why they are used in if statements, since the value must be true or false/nil
so if (x==2) then
really means
if false then
And no if statement that have only false inputs (disreguarding not's and or's) will not be triggered. Just thought you might want some explaination of why they are used like this :) |
|
|
| Report Abuse |
|
|
|
| 24 Feb 2012 09:09 PM |
| Ugh, sorry for the late post; the person above me got to ya first :P |
|
|
| Report Abuse |
|
|
XNoBoomX
|
  |
| Joined: 08 May 2011 |
| Total Posts: 4731 |
|
|
| 24 Feb 2012 09:12 PM |
Oh no, there's another C&G'er here.
~{An Intellectual In Love With Bacon}~ |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 24 Feb 2012 10:09 PM |
@Counter
if script.Parent.BrickColor == BrickColor.new("ColorHere") then
You say it like that. |
|
|
| Report Abuse |
|
|
|
| 24 Feb 2012 10:11 PM |
| I'm not trying to make it change the color though, but merely detect and confirm it in the form of an if statement. I know I could just print it if I really wanted, and all that jive, but this is just a test of the logic behind if statements really. Not going to use it after this really. |
|
|
| Report Abuse |
|
|
|
| 24 Feb 2012 10:16 PM |
| You use '==' WAY more than you'd think. Why? because half the other operators compare numbers. ~= and == can compare anything. |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 24 Feb 2012 10:20 PM |
| You'll use statements a lot. They're useful and the basics of coding. They're in a lot of other languages too. |
|
|
| Report Abuse |
|
|
|
| 24 Feb 2012 10:54 PM |
^
Yeah, if only most programming languages allowed you to make events, without being a binary genius. :P |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 24 Feb 2012 10:55 PM |
I know right :P
Though, it does make sense how they DON'T have events. |
|
|
| Report Abuse |
|
|
|
| 24 Feb 2012 11:37 PM |
"Yeah, if only most programming languages allowed you to make events, without being a binary genius. :P"
If there's no events, none are needed and none will ever be needed. It depends on the type of language; would you need events added to XML? |
|
|
| Report Abuse |
|
|
|
| 24 Feb 2012 11:38 PM |
| Yeah, but when you're heavily scripting your Roblox game, you really want custom events. Though, unless it's like an if statement, designing it would be a pain. |
|
|
| Report Abuse |
|
|
|
| 24 Feb 2012 11:39 PM |
| When you're heavily scripting your Roblox game, you're not *using* other languages besides RBX.Lua, which does in fact let you make custom events. |
|
|
| Report Abuse |
|
|
|
| 24 Feb 2012 11:42 PM |
| Well, I don't really know how to make DLL's so I wouldn't know how the heck to do that, but even in the languages that I'm really good at, I don't know how the heck you make custom events. |
|
|
| Report Abuse |
|
|
|
| 24 Feb 2012 11:44 PM |
"Well, I don't really know how to make DLL's so I wouldn't know how the heck to do that,"
DLLs have nothing to do with this.
"but even in the languages that I'm really good at, I don't know how the heck you make custom events."
What languages are you really good at that you have in mind? |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
| |
|
| |
|
|
| 25 Feb 2012 04:07 PM |
| http://docs.oracle.com/javase/tutorial/uiswing/events/index.html |
|
|
| Report Abuse |
|
|
| |
|