Sunday, 08 March 2009

Hi all

So, I have written two previous posts about how to solve the If-Then-Else problem in a map. The first post discussed the way to use built-in functoids to solve the issue. The second post discussed the issues I had creating a custom functoid to do the job.

Well, I now have a new way of doing it, which is not just one functoid, but still it's prettier than what I can do with the built-in functoids.

Basically, as discussed in my post about the issues with the different functoid categories, a functoid that is in the String category cannot accept a logical functoid as input. A scripting functoid can accept a logical functoid as input, but I can't create a custom scripting functoid where I decide what script to appear inside the scripting functoid at design time.

So the solution I am describing in this post is a combination of the two.

This screenshot describes a map that solves the If-Then-Else problem:

IfThenElse

The blue functoid with the crappy icon is programmed by myself. It is a simple functoid, which takes in three parameters, which are all strings. First, it tries to convert the first parameter to a boolean. If this fails, a "false" is assumed. Then, if the boolean was true, the second parameter is returned and if it was false, the third parameter is returned.

Now, since a string functoid cannot take a logical functoid as an input, I use a custom scripting functoid that is very simple:

public string Same(string str)
{
return str;
}

Which is really annoying to have to do, since... well... I take in a string and return the exact same string. Oh well...

You can find my functoid and the project that uses it as file downloads at the bottom of this post. Note, that the functoid library contains a whole bunch of functoids, of which only one is relevant. The library contains all the functoids I built trying to solve the If-Then-Else issue. The only needed functoid will be included in my downloadable functoid library at a later point.

Now, the advantages of this solution is, that it only requires three functoids all together. The best I could do with the built-in functoids were four, and five were sometimes the prettiest solution.

Functoid library: here

Project that uses the functoid: here

--
eliasen

Sunday, 08 March 2009 22:02:37 (Romance Standard Time, UTC+01:00)  #    Comments [2]  | 

Theme design by Jelle Druyts