whoami 26 Posted July 3, 2014 Report Share Posted July 3, 2014 Hello guys..Im doing functions to refactor my code and make it more clean. But I am struggling on how to do it with UBot.I am doing this: define $Sanitize companies variables(#sanitize_companies) { set(#sanitize_companies, $trim(#sanitize_companies), "Global") set(#sanitize_companies, $replace(#sanitize_companies, ",", ". "), "Global") set(#sanitize_companies, $replace(#sanitize_companies, "\"", $nothing), "Global") return(#sanitize_companies) } And testing it with this: set(#company_name, "\"something with\" and some, commas that define, more content and finally another \"", "Global") set(#company_name, $Sanitize companies variables(#company_name), "Global") Its not working for me,I know I am doing something wrong but I cannot detect it. Quote Link to post Share on other sites
Marton 48 Posted July 3, 2014 Report Share Posted July 3, 2014 When adding a parameter to a function, you don't need to pass it to a variable from inside the function, you can just use it as is (it's a common misconception, most tutorials are quite misleading about this). Here you go, try this: set(#company_name, "\"something with\" and some, commas that define, more content and finally another \"", "Global")set(#company_name, $Sanitize companies variables(#company_name), "Global")define $Sanitize companies variables(#sanitize_companies) { return($replace($replace($trim(#sanitize_companies), ",", "."), "\"", $nothing))} Let me know if you have any questions. Marton p.s.: if any mod reads this, I think this topic should be moved to Scripting main forums Quote Link to post Share on other sites
whoami 26 Posted July 3, 2014 Author Report Share Posted July 3, 2014 Wow, thanks a lot.So my mistake was setting(using set) inside the function instead of clearly just returning concatenated functions.Right? Quote Link to post Share on other sites
Marton 48 Posted July 3, 2014 Report Share Posted July 3, 2014 Wow, thanks a lot.So my mistake was setting(using set) inside the function instead of clearly just returning concatenated functions.Right? No problem. Well, I wouldn't call it a mistake, but it's not needed. You can fix your original code by changing all three set commands in your function to "Local". Try it, it will work. Mine is just a bit more optimized, that's all. Marton Quote Link to post Share on other sites
whoami 26 Posted July 3, 2014 Author Report Share Posted July 3, 2014 Your method is what I want to learn eventually.Those smart decisions for refactoring.Where can I learn more about it?How can I google that for javascript or PHP? Quote Link to post Share on other sites
the_way 52 Posted July 3, 2014 Report Share Posted July 3, 2014 when is it required to use that methodology with the internal sets? Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.