Message Board
Message Board > Fenix / Bennu / Gemix / DIV > string functions |
November 10, 2006, 10:02 | |
t money
MRF 22 posts |
i don't know how many people have written functions that return strings in fenix, but i've been having problems getting them to work. it's weird because i've come to realize that if you want to have a function return a string, it must be placed in your code before the function/process that calls it. maybe this is old news to most people, but i'm used to div where it didn't matter where the code was placed. presumably, fenix defaults all functions to return ints so any function coming before another function will assume the latter is returning an int. so to be clear, this won't work: _______________________ Code: FUNCTION i_get_text(); PRIVATE string my_text; BEGIN my_text=i_give_text(); END FUNCTION STRING i_give_text(); BEGIN RETURN("hello world"); END _______________________ but if you put the functions the other way it does work: _______________________ Code: FUNCTION STRING i_give_text();
BEGIN RETURN("hello world"); END FUNCTION i_get_text(); PRIVATE string my_text; BEGIN my_text=i_give_text(); END ____________ surrogate: wink... did you say wink, or did you wink? michael: he said that too dad. |
# |
November 10, 2006, 10:45 | |
Dennis
どこかにいる 2092 posts |
I think it's always best to write "int" everywhere, except when you don't return a variable. In Fenix using the "int" data type is possible. basically I advice you to use this rules: Code: //always use the int datatype, even for reserved words global int some_highscore; int var; string hello; etc... //place datatype when you return something function string i_give_text() begin return "hi everybody!"; end //for ints this is optional but do it anyway, it's clearer function int i_give_variable() private int hax = 78; begin return hax; end //since the "void" datatype you can use nothing instead //this is still "int" by default though returning is optional in Fenix function i_give_nothing() begin hello = "hi"; end It's a good thing you mentioned this, it will prevent people making mistakes in the future. PS: I can't use FUNCTION in fenix verison 0.84a but if you can use string, you can use int, I reckon. [Edited on November 10, 2006 by Dennis] ____________ Kwakkel |
# |
Message Board > Fenix / Bennu / Gemix / DIV > string functions