PDA

View Full Version : Syntax question


ronviers
01-07-2008, 10:41 AM
$patches_v=5;
$patch_v=1/$patches_v;

Why does this return a result of zero rather than .2?

Thank you,
Ron

geonak
01-07-2008, 10:48 AM
$patches_v=5;
$patch_v=1/$patches_v;

Why does this return a result of zero rather than .2?

Thank you,
Ron

this is because the way you wrote it it returns an integer
to make it return a float just do $patch_v=1.0/$patches_v;

hope it helps

ronviers
01-07-2008, 10:52 AM
Thank you geoknak,

But I still get a result of zero.

I really hate to ask a question like this, I was just in a hurry to get on with the rest of the script and I got completely bogged down with this simple issue.

Fumetsu
01-07-2008, 11:17 AM
Hello Ron,

Try this

float $result;
$patches_v=5.0;
$result = ($patch_v=1/$patches_v);

ronviers
01-07-2008, 11:29 AM
I can't believe it aashroff but I still get a zero.

I tried it just as you said but I actually want the $patches_v to be int and I want $patch_v to be float.

I have tried it in so many ways now I'm running out of combinations.

Thank you

Fumetsu
01-07-2008, 11:56 AM
Ron,

This is the only way i could come up with.

$patches_v=5;
print(float($patch_v=1)/$patches_v);

I am quite curious now to know this myself :P

Hopefully some experts will be able to help you out.

ronviers
01-07-2008, 12:06 PM
Now I'm really confused. Here is the next line (at least this is how it exists in my mind), and I I am not sure how that $patch_v/2 will be .1 and I need $patch_v_mid to be .1.

$patches_v=5;
$patch_v=1/$patches_v;
$patch_v_mid=$patch_v/2;


Thank for taking a look at this. I will keep working the problem and if I figure anything out I will post back here. Like you said, hopefully someone else will have a way.

mfg
01-07-2008, 12:08 PM
hi,

this worked for me,

-------------------------------
float $patch_v,$result;
int $patches_v;

$patch_v = 1.2;
$patches_v = 5;

$result = $patch_v/$patches_v;
-------------------------------

but i also had some very strange maya behavior, i also kept getting result 0.
restarted maya tried again and then it worked...

GiantG
01-07-2008, 12:19 PM
{
int $patches_v = 5;
float $patch_v = 1.0/$patches_v;
$patch_v_mid = $patch_v/2;
print $patch_v_mid;
}

ronviers
01-07-2008, 12:37 PM
That works GiantG Thank you.

I'm not happy about how far off I was. It does not give me a lot of confidence about the rest of the lines I wrote.

I am still going to look for a way for $patches_v to be int just because the number of nurbs patches will always be ints. I also hope I can find a way to declare the other variables as floats without having to type float on each line.

I guess I need to take a step back and spend more time accumulating mel resources so it will be easier to find answers like this on my own.

GiantG
01-07-2008, 12:53 PM
After reading the Thread more exactly...You have to use 1.0 instead of 1:

{
int $patches_v = 5;
float $patch_v = 1.0/$patches_v;
$patch_v_mid = $patch_v/2;
print $patch_v_mid;
}

ronviers
01-07-2008, 01:03 PM
Getting better all the time:)

Thanks to you and geonak and aashroff for getting me back on track.

CarlRiver
01-07-2008, 01:45 PM
Maya is doing the calculation on the right side as an integer operation. If you write $patch_v = 1/float($patches_v); this works just as expected.
This is a reason why I don't like programs that allow you to use undeclared variables.

Fumetsu
01-07-2008, 02:33 PM
Glad you got it to work! :thumbsup:

ronviers
01-07-2008, 10:15 PM
Ok, don't laugh; this is what I came up with. It works but I wonder if this way of handling variables will get me into trouble later on. Obviously I need to add a loop but what I'm thinking about now is just variables. Does anyone have an opinion about whether this looks correct?





global int $patches_v=5;

global float $patch_v;

{

$patch_v=1.0/$patches_v;

$patch_v_mid=$patch_v/2;

$patch_v_mid_1=$patch_v_mid*$patches_v;

$patch_v_mid_2=$patch_v_mid_1+$patch_v*$patches_v;

$patch_v_mid_3=$patch_v_mid_2+$patch_v*$patches_v;

$patch_v_mid_4=$patch_v_mid_3+$patch_v*$patches_v;

$patch_v_mid_5=$patch_v_mid_4+$patch_v*$patches_v;

//etc.

print $patches_v;

print $patch_v;

print $patch_v_mid;

print $patch_v_mid_1;

print $patch_v_mid_2;

print $patch_v_mid_3;

print $patch_v_mid_4;

print $patch_v_mid_5;

}





Btw, mfg; I'm noticing the same strange behavior. It may be just me but Maya seems to be a little touchy about reusing variable. I can't figure out just when it's allowed and how to recycle them without restarting Maya.

Thanks everyone,
Ron

CGTalk Moderation
01-07-2008, 10:15 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.