[SOLVED]Please explain this math.

If you have problems installing or running Algodoo, have found a bug or need in-game help - this is it!

[SOLVED]Please explain this math.

Postby Xray » Sat Dec 08, 2012 6:57 pm

When I add two variables, I get the result that I expect. For example:
a = 1;
b = 2;
a + b == 3

But when I add a variable to an array element, I do not get the result that I expect. For example:

a = 1;
b = 2;
scene.my.array = [3];
a + b + scene.my.array(0) == 123 :crazy:

Take a look at the scene I included here and explain WHY this is happening. If this is not a bug, then please explain how I can add a variable and an array element, and come up with the result that I would expect.

Thanks
Attachments
What's Happening_.phz
(13.18 KiB) Downloaded 22 times
User avatar
Xray
 
Posts: 501
Joined: Sun Jun 17, 2012 6:12 am
Location: USA

Re: Please explain this math.

Postby electronicboy » Sat Dec 08, 2012 8:22 pm

Seams like an issue with the way text is evaluated.

Open the script menu of the box, and type the following into
Code: Select all
_c = _a + _b + scene.my.array(0)


as a workaround, just use a laser or use another method to create the variable needed.
In the next version of algodoo, it seams like we will be able to run code without requiring an laser or collision driven event!
When asking for help, READ THE STICKIES!
electronicboy
 
Posts: 1694
Joined: Mon Aug 31, 2009 6:18 pm

Re: Please explain this math.

Postby Xray » Sat Dec 08, 2012 8:39 pm

electronicboy wrote:Seams like an issue with the way text is evaluated.

Open the script menu of the box, and type the following into
Code: Select all
_c = _a + _b + scene.my.array(0)


as a workaround, just use a laser or use another method to create the variable needed.
In the next version of algodoo, it seams like we will be able to run code without requiring an laser or collision driven event!


This isn't text! The same thing occurs when adding variables and array elements in OnCollide, and HitByLaser, and even in the console. TRY IT!

EDIT: I just now tried it again in OnCollide and it worked correctly. I don't know why I got a crazy answer earlier when I tried it, but now it's coming up with the correct answer. I believe you are right about it having something to do with TEXT. It seems to give the correct answer except when calculated in a text box.
User avatar
Xray
 
Posts: 501
Joined: Sun Jun 17, 2012 6:12 am
Location: USA

Re: Please explain this math.

Postby Kilinich » Sat Dec 08, 2012 9:13 pm

one of your variables was text not number, but you can't see it in console - a = "1" and a = 1 will looks like 1
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: Please explain this math.

Postby Xray » Sat Dec 08, 2012 9:18 pm

Kilinich wrote:one of your variables was text not number, but you can't see it in console - a = "1" and a = 1 will looks like 1


Yes, I just now realized that. So, apparently, if even ONE of the variables is text, then ALL of the variables are evaluated as text.

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

Re: [SOLVED]Please explain this math.

Postby tatt61880 » Sun Dec 09, 2012 1:35 am

Added [SOLVED] in this topic title ;)
NOTE: I'm not an Algoryx member.
Hi, Algodoo lovers. Have you read next topic? Featured scenes suggestions
To translators: English.cfg changelog will be useful (even for me).
User avatar
tatt61880
[Most Helpful Person 2010]
 
Posts: 1150
Joined: Mon Aug 31, 2009 5:45 pm
Location: Tokyo, Japan

Re: [SOLVED]Please explain this math.

Postby Xray » Sun Dec 09, 2012 1:37 am

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


Return to Help / Bug reports

Who is online

Users browsing this forum: No registered users and 2 guests