SimplyMaya Forums

Welcome to the forum, feel free to ask questions here.

Register FAQ Members List Calendar Mark Forums Read

New Thread
 
Thread Tools
Old 29-03-2006, 01:57 AM   #1
mayakid14
Registered User
 
mayakid14's Avatar
 
Join Date: Nov 2004
Location: Florida
Posts: 105
Thanks: 0
Thanked 0 Times in 0 Posts
Default String to Int

Does anyone know if there is a way to convert a string to an int or a float.
Example:

string $mystring = "15";
int $myint = ($mystring - 1);
print $myint;

Maya doesn't execute this script because $mystring doesn't really have a int value. In BASIC I think this concept would be written as:
Dim mystring As string = "15"
Dim myint As integer = (val(mystring) - 1)
MsgBox(myint)
The VAL function works in BASIC but it won't work in MEL. Of course it doesn't seem like MEL hasa VAL function but is there an alternative?
__________________
I hope you didn't waste your time reading this line.
mayakid14 is offline   Reply With Quote
Old 29-03-2006, 08:23 AM   #2
Alan
Moderator
 
Alan's Avatar
 
Join Date: Oct 2002
Location: London, UK
Posts: 2,800
Thanks: 0
Thanked 5 Times in 5 Posts
Default

you're talking about casting.

you can cast a string like this:

string $strVal = "150000";
int $intVal = (int)$strVal;
float $floatVal = (float)$strVal;


and you can go the other way too:

int $intVal = 1545;
string $strVal = (string)$intVal;


A
__________________
Technical Director - Framestore

Currently working on: Your Highness

IMDB
Alan is offline   Reply With Quote
Old 29-03-2006, 01:35 PM   #3
mayakid14
Registered User
 
mayakid14's Avatar
 
Join Date: Nov 2004
Location: Florida
Posts: 105
Thanks: 0
Thanked 0 Times in 0 Posts
Talking

Whoa thanks a bunch. Never thought there would be a way for this. Couldn't find anything in the reference commands or anything.
You're Awsome
__________________
I hope you didn't waste your time reading this line.
mayakid14 is offline   Reply With Quote
Old 29-03-2006, 02:12 PM   #4
Alan
Moderator
 
Alan's Avatar
 
Join Date: Oct 2002
Location: London, UK
Posts: 2,800
Thanks: 0
Thanked 5 Times in 5 Posts
Default

no problem. Casting is common in many programming languages.


A
__________________
Technical Director - Framestore

Currently working on: Your Highness

IMDB
Alan is offline   Reply With Quote
New Thread

« Previous Thread | Next Thread »

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off

1 Month

$34

Month-to-month billing
$34/month
Unlimited access to all videos
Project files to download
Easy to cancel at anytime
 
 

3 months

$87

Billing every 3 months
$29/month
Unlimited access to all videos
Project files to download
Easy to cancel at anytime
Save $5 per month or $15 in total compared to monthly billing with this package.

12 months

$288

Billing every 12 months
$24/month
Unlimited access to all videos
Project files to download
Easy to cancel at anytime
Save $10 per month or $120 in total compared to monthly billing with this package.

Your plan will automatically renew. You can cancel at any time via your PayPal account to avoid being charged again.

You can view the FAQ on our video plans here. You can contact us directly here. By clicking one of the buttons above, you agree to our Terms and Privacy Policy.