|
How to check the text assigned to a Variable
|
|
02-08-2013, 08:22 PM
Post: #1
|
|||
|
|||
|
How to check the text assigned to a Variable
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 |
|||
|
02-08-2013, 09:32 PM
(This post was last modified: 02-08-2013 09:35 PM by micheus.)
Post: #2
|
|||
|
|||
RE: How to check the text assigned to a Variable
(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,"_"), |
|||
|
02-08-2013, 10:32 PM
Post: #3
|
|||
|
|||
|
RE: How to check the text assigned to a Variable
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"/> |
|||
|
02-09-2013, 11:32 AM
Post: #4
|
|||
|
|||
|
RE: How to check the text assigned to a Variable
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: ... |
|||
|
02-10-2013, 03:08 AM
Post: #5
|
|||
|
|||
|
RE: How to check the text assigned to a Variable
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.
|
|||
|
02-11-2013, 08:00 AM
Post: #6
|
|||
|
|||
|
RE: How to check the text assigned to a Variable
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...
|
|||
|
02-11-2013, 03:49 PM
Post: #7
|
|||
|
|||
RE: How to check the text assigned to a Variable
(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 |
|||
|
02-11-2013, 07:49 PM
Post: #8
|
|||
|
|||
|
RE: How to check the text assigned to a Variable
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 |
|||
|
10-27-2013, 01:45 PM
Post: #9
|
|||
|
|||
|
RE: How to check the text assigned to a Variable
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 ?
|
|||
|
10-27-2013, 02:41 PM
Post: #10
|
|||
|
|||
|
RE: How to check the text assigned to a Variable
No. Check the Erlang Programming Rules - Variable Names
|
|||
|
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)





If the function was working I would get either "taco" or "bell" but I get neither.