How to check the text assigned to a Variable - Printable Version +- Wings 3D Development Forum (https://www.wings3d.com/forum) +-- Forum: Wings 3D (https://www.wings3d.com/forum/forumdisplay.php?fid=1) +--- Forum: Programming (https://www.wings3d.com/forum/forumdisplay.php?fid=7) +--- Thread: How to check the text assigned to a Variable (/showthread.php?tid=178) Pages:
1
2
|
How to check the text assigned to a Variable - oort - 02-08-2013 How do I check the text assigned to a Variable? This is probably simple but I can't find any info that will help me. I decided to go ahead and add Blend modes (add,multiply,subtract,etc.) to the YafaRay plug-in before taking on the task of cleaning up my code. I made the mistake of thinking it would be simple... 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. Quote: UpperLayer = I have tried lots of stuff but the above was my last try. When I export the .xml file from Wings3D I get the following... Quote:<diffuse_shader sval="w_default_Bronze_1"/> The blank line above <type sval="layer"/> is where I need to add code. I am using "taco" and "bell" for testing purposes.... If the function was working I would get either "taco" or "bell" but I get neither. Thanks, oort RE: How to check the text assigned to a Variable - micheus - 02-08-2013 (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. 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,"_"), This can crash Wings if you can get an invalid number to Num: Code: Tokens=string:tokens(Texname,"_"), RE: How to check the text assigned to a Variable - oort - 02-08-2013 Micheus, Thanks for helping. That doesn't give me exactly what I need. I need to clarify what I need... For w_default_Bronze_1 I need to get the following text added to the exported .xml file... Quote:<upper_layer sval="w_default_Bronze_2"/> and for w_default_Bronze_2 I need " " (no text) added to the exported .xml file. Below is what I am trying to get in my .xml file, although this may not be exactly what the final code needs to be. Thanks, oort Quote: <diffuse_shader sval="w_default_Bronze_1"/> RE: How to check the text assigned to a Variable - micheus - 02-09-2013 Sorry. (02-08-2013, 10:32 PM)oort Wrote: For w_default_Bronze_1 I need to get the following text added to the exported .xml file...Let see if I am right now... Code: ... Code: ... Code: ... In case you can have other declarations it would be better try to create something more generic. By using the last example, we could create a function and use it like follow: Code: ... RE: How to check the text assigned to a Variable - ggaliens - 02-10-2013 Use a real XML parser or write one. It should be trival. I've done it a few times and if you do it right ... to handle very basics ... you don't need much code. RE: How to check the text assigned to a Variable - oort - 02-11-2013 Micheus, Thanks... I ended up having to use Split instead of Tokens. I was getting my "1" and "2" but it was not recognized as an integer so "UpperLayer" was not being defined. It took me a while to figure it out but it is working now. Since Blend modes can only have two textures in YafaRay I can probably use the simpler version of your code for now. Unless further testing proves that it is needed... Thanks again! oort Quote:%% Start Identify Modulator # (w_default_Bronze_1 or w_default_Bronze_2) ggaliens, No idea what a real xml parser does but I am sure it would require skills I do not yet have... RE: How to check the text assigned to a Variable - micheus - 02-11-2013 (02-11-2013, 08:00 AM)oort Wrote: I ended up having to use Split instead of Tokens.ggaliens had introduced me re before, but I always forget about it. About the xml management, I already thought to suggest it too, but I know how complicated can be learn something new when we are capable to get the same result using what we know. I think, that after you finish coding the plugin, you could take a look about use a xml builder in order to optimize/organize your final code - think it as a version review. As I saw in the yafaray documentation: Quote:Each XML document should start with naming the XML version: <?xml version="1.0"?> it's xml 1.0 compliant, so you can use xmerl module for that. Here you have a simple example how to generate an xml file from Erlang. /Micheus RE: How to check the text assigned to a Variable - oort - 02-11-2013 Micheus, Thanks for the info on the xmerl module. I may use that to clean up my exported xml code. Yes, something to do after I finish coding the plug-in... oort RE: How to check the text assigned to a Variable - Whimad - 10-27-2013 Does each variable must have a unique name, and access its value by using that name. When you choose a name for a variable, the first character must be one of the letters A through Z, !, ?, @, #, $, or _. Any remaining characters of the variable's name can be any of the preceding characters as well as 0 to 9 ? RE: How to check the text assigned to a Variable - micheus - 10-27-2013 No. Check the Erlang Programming Rules - Variable Names |