Declaring Variables and Identifiers

About advanced scenes, and the Thyme scripting language used in Algodoo.

Declaring Variables and Identifiers

Postby Xray » Thu Jul 05, 2012 6:49 am

I read the "Tyme Tutorial - with explanations at every step" concerning declaring variables and identifiers, and I was just as confused after reading it as I was before reading it! The tutorial states that "a variable is something that holds something, like a number....." and "An identifier is the name of your variable". Okay, so let's say I create a variable called VAR, and I use the following syntax: scene.my.var = 5. I created a variable named var, and it contains the value 5. If I understand the tutorial correctly, the name of the variable "var" is the identifier. Okay, so far. Now in Tutorial 3 "Declaring a new identifier", it states that I must use the syntax: scene.my.var2 := 7, which will create a new variable named var2, and it contains the value 7. If I want to confirm that those variables contain those values, I can use the syntax: "scene.my.var" and "scene.my.var2". The result will show 5 and 7. Now if I wanted to change the value of either of those variables, I can simply stick a new value in either of them with: scene.my.var = whatever and scene.my.var2 = whatever. So, what the heck is the difference between a variable name and an identifier? It seems that I can use the two interchangeably, except that I cannot change the value of a variable that has already been declared by using the ":=". I can only change the value by using "=". So, what's the point? Why even bother with declaring a new identifier when declaring a variable is just as simple, but doesn't have the restriction imposed by declaring an identifier? AAARRRRGH! :crazy:
User avatar
Xray
 
Posts: 501
Joined: Sun Jun 17, 2012 6:12 am
Location: USA

Re: Declaring Variables and Identifiers

Postby Kilinich » Thu Jul 05, 2012 7:41 am

Variable and Identifier is the same term I suppose.
:= and = is differ if you use complex code with same variables, for example you should always use := then creating new geoms. scene.addBox(pos := [0,0])
Dream of Algodoo as game development engine...
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2098
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia

Re: Declaring Variables and Identifiers

Postby Xray » Thu Jul 05, 2012 4:47 pm

Kilinich wrote:Variable and Identifier is the same term I suppose.
:= and = is differ if you use complex code with same variables, for example you should always use := then creating new geoms. scene.addBox(pos := [0,0])


Kilinich - Thanks for your reply, but I'm still a little hazy about it. Your answer states that I should use := when using "complex code", but you do not explain WHY. Also, what defines "complex code"? Is it a program with, say, more than 100 lines of code? If I use "=" instead of := when declaring variables in complex code, what might happen? Is it simply a matter of the program guarding me so that I do not overwrite a variable by defining it more than once?

Thanks
User avatar
Xray
 
Posts: 501
Joined: Sun Jun 17, 2012 6:12 am
Location: USA


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 2 guests