probiner Posted January 21, 2020 Share Posted January 21, 2020 (edited) One thing that throws me off the road with VEX is issues with operations not being overaloaded/able or not have the ability to drive the type cast of a variable. Kills abstractness and makes for some cumbersome code. I've used in the past a trick to get the variable assignment to be programmatically driven(float, vector...etc) instead of scooped in a sucession of else ifs that lead to duplicated code: if(caracteristic == 0){ float var = attrib(0,class, name, @elemnum) ; < code body> } else if(caracteristic == 1){ vector2 var = attrib(0,class, name, @elemnum) ; < code body> } else if(caracteristic == 2){ vector var = attrib(0,class, name, @elemnum) ; < code body> } .... .... .... Instead just have `chs("type")` var = attrib(0,class, name, @elemnum) ; < code body> Which will result in var being casted based on parameter, and also not being scoped and therefore no code duplication for each case. Now while seems great, I've noticed it takes way more time to cook than the else ifs way.- Therefore I was wondering if there is a way to do this driven variable assignment with preprocessors. The code still might look ugly but at least the execution part will be a single one for all types. #define var 100.0 This for example sets var as a float. But I wonder how I can inform it which variable type it should have. Thanks Edited January 21, 2020 by probiner Quote Link to comment Share on other sites More sharing options...
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.
Note: Your post will require moderator approval before it will be visible.