View Full Version : Number Boolean Problem
Gazurt
October 12th, 2007, 05:05 AM
My little code:
var hsp = !((76-24)/(80-60)-(85-24)/(120-60)<0) ^ (60<=80 == 60>120);
trace(hsp);
In AS2 there is no problem but in AS3 error is like this:
1067# Implicit coercion of a value of type Boolean to an unrelated type Number
What is the problem? Thanks...
Aquilonian
October 12th, 2007, 05:59 AM
The problem is that hsp can be only true or false,there is not anymore such things as 'if its 0 them assume its false' wich is a very good thing, i always hated when i was trying to learn a code and there was a variable set to be one thing and used like another one, so unnorganized
Gazurt
October 12th, 2007, 06:20 AM
I think you say this:
my_mc.visible=0;
In AS3 this is wrong? Understood... But I don't how to write this in AS3 style :P
;
var hsp:Number = (((76-24)/(80-60)-(85-24)/(120-60)<0) ^ (60<=80 == 60>120));
trace(hsp);
Aquilonian
October 12th, 2007, 07:33 AM
yes it is
its simple,you could go like this
if( (((76-24)/(80-60)-(85-24)/(120-60)<0) ^ (60<=80 == 60>120)) == 0){
hsp = false;
}else{
hsp = true
}
Charleh
October 12th, 2007, 07:56 AM
Just use explicit type conversion
Gazurt
October 12th, 2007, 10:16 AM
yes it is
its simple,you could go like this
if( (((76-24)/(80-60)-(85-24)/(120-60)<0) ^ (60<=80 == 60>120)) == 0){
hsp = false;
}else{
hsp = true
}
I wrote the code like this:
var hsp:Boolean;
if ( (((76-24)/(80-60)-(85-24)/(120-60)<0) ^ (60<=80 == 60>120)) == 0) {
hsp = false;
} else {
hsp = true;
}
And gives same error :puzzle: @Charleh can you tell me what explicit type conversion is? I don't know it :(
Charleh
October 12th, 2007, 10:43 AM
Well I don't understand what that code is ... but
hsp = Boolean((!((76-24)/(80-60)-(85-24)/(120-60)<0) ^ (60<=80 == 60>120));
Might work - it should convert the 1 or 0 to a boolean value before assigning it to the variable. Doing this in code is known as explicit conversion. When the compiler does it at run time it's known as implicit conversion.
Even so I reckon it probably still won't work. I think it's moaning more about your expression rather than the variable type - what exactly are you trying to do?! What are these numbers?
Gazurt
October 12th, 2007, 11:41 AM
I wrote a 3D Class in AS2... Now I am converting it o AS3.For performances I am using code...
ahw I can't tell it :m: But look here:
http://blog.codesignist.com/data/e3d3/normal.html
Maybe you can understand what I am trying to do :)
Charleh
October 12th, 2007, 11:58 AM
Nope - still don't understand - a normal is the vector which is perpendicular to a plane or face - your normal calculation returns 1 or 0 - is it supposed to find which side of the triangle the normal is facing?
There are easier ways of calculating a normal - plus that's in 2D - wheres the 3D bit?
Gazurt
October 12th, 2007, 12:05 PM
1 Mean:
You see the object's face
0 Mean:
You don't see the object's face
I am using triangle facing...
Gazurt
October 12th, 2007, 12:16 PM
Also senocular uses it...
Look here: http://www.kirupa.com/developer/actionscript/solid_pyramids.htm
Following that, the visibility function can be added. This will be used in the first pyramid for backface culling taking three of the points making up a face in the pyramid and determining visibility of that face based on slope and position of each point in relation to each other. The second pyramid will not use this function in favor of having each face as a movieclip and using swapDepths to properly overlap each face.
isVisibleBetween = function (a, b, c) {
if (((b._y-a._y)/(b._x-a._x)-(c._y-a._y)/(c._x-a._x)<0) ^ (a._x<=b._x == a._x>c._x)) {
return true;
} else {
return false;
}
};};
Gazurt
October 12th, 2007, 07:59 PM
Can someone help me? :puzzle:
Ordinathorreur
October 14th, 2007, 10:16 AM
So what does your code look like now? Still the same as your first post?
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.