• Website
  • Search
  • Member List
  • Help
  • Old Forum
  • Social Media
    •   @Wings3dOfficial
    •   @Wings3dOfficial
    •   Wings3dOfficial
    •   Wings3dOfficial
  • Register
  • Login
  • Website
  • Search
  • Member List
  • Help
  • Old Forum
  • Register
  • Login
Wings 3D Development Forum Wings 3D Programming v
« Previous 1 2 3 4 Next »
How to check the text assigned to a Variable

 
  • 1 Vote(s) - 5 Average
How to check the text assigned to a Variable

micheus
Offline

Forum's Admin and Support | Bug fixer
Posts: 3,682
Threads: 185
Joined: Jun 2012
#2
02-08-2013, 09:32 PM (This post was last modified: 02-08-2013, 09:35 PM by micheus.)
(02-08-2013, 08:22 PM)oort Wrote: Texname is the variable that gets assigned a name (w_default_Bronze_1 or w_default_Bronze_2). I need to check to see if I am working with w_default_Bronze_1 or if I am working with w_default_Bronze_2. I need to know this because they have to be handled differently when exporting them for YafaRay.
Probably someone could put a different code - it always possible use different ways - I'll left two that works. Smile

This one will check for fail (but, I don't think you need to check if is number, since you have formated the string before):
Code:
Tokens=string:tokens(Texname,"_"),
    Num=lists:last(Tokens),
    case string:to_integer(Num) of
        {error, _} -> io:format("Conversion error\n",[]);
        {1, _} -> io:format("Item 1 selected\n",[]);
        {2, _} -> io:format("Item 2 selected\n",[])
    end,
For Texname="w_default_Bronze_2" tokens will return ["w","default","Bronze","2"].

This can crash Wings if you can get an invalid number to Num:
Code:
Tokens=string:tokens(Texname,"_"),
    Num=lists:last(Tokens),
    case list_to_integer(Num) of
        1 -> io:format("Item 1 selected\n",[]);
        2 -> io:format("Item 2 selected\n",[]);
        N -> io:format("Item ~p selected\n",[N])
    end,
Function references - check than to understand what each one do:
  • string:tokens()
  • string:to_integer()
  • lists:last()
  • list_to_integer()
« Next Oldest | Next Newest »

Users browsing this thread: 1 Guest(s)



Messages In This Thread
How to check the text assigned to a Variable - by oort - 02-08-2013, 08:22 PM
RE: How to check the text assigned to a Variable - by micheus - 02-08-2013, 09:32 PM
RE: How to check the text assigned to a Variable - by oort - 02-08-2013, 10:32 PM
RE: How to check the text assigned to a Variable - by micheus - 02-09-2013, 11:32 AM
RE: How to check the text assigned to a Variable - by ggaliens - 02-10-2013, 03:08 AM
RE: How to check the text assigned to a Variable - by oort - 02-11-2013, 08:00 AM
RE: How to check the text assigned to a Variable - by micheus - 02-11-2013, 03:49 PM
RE: How to check the text assigned to a Variable - by oort - 02-11-2013, 07:49 PM
RE: How to check the text assigned to a Variable - by Whimad - 10-27-2013, 01:45 PM
RE: How to check the text assigned to a Variable - by micheus - 10-27-2013, 02:41 PM
RE: How to check the text assigned to a Variable - by superhitdeals - 04-04-2014, 12:52 PM
RE: How to check the text assigned to a Variable - by martinkay - 06-30-2014, 01:44 PM

  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Designed by D&D - Powered by MyBB

Linear Mode
Threaded Mode