| 04-04-2005, 12:42 PM | #1 |
Ok i have this JASS trigger. function JQK_Factor takes integer Card returns string local string CurrentCard_String if (Card == 11) then set CurrentCard_String = "J" else endif if ( Card == 12 ) then set CurrentCard_String = "Q" else endif if ( Card == 0 ) then set CurrentCard_String = "K" else endif if ( Card == 1 ) then set CurrentCard_String = "A" else endif return CurrentCard_String set CurrentCard_String = null endfunction and when the trigger looks like this it gives me an error "Function must have a return value" or something like that. It works when I remove the last line "set CurrentCard_String = null"(but that causes memorly leaks) so I was wondering how do I null a variable that is the return value of the function? I mean I just can't have to put up with memory leaks do I? Strangly enough when the last 3 lines look like this, It works. return CurrentCard_String set CurrentCard_String = null return CurrentCard_String but knowing how I had a problem before it makes me wonder if its nulling the variable or if it just returns the value then stops the function. Well thanks in advance. |
| 04-04-2005, 01:45 PM | #2 |
Well, in this particular case you could rewrite the function like this: Code:
function JQK_Factor takes integer Card returns string if (Card == 11) then return "J" else endif if ( Card == 12 ) then return "Q" else endif if ( Card == 0 ) then return "K" else endif if ( Card == 1 ) then return "A" else endif return "" endfunction Code:
function JQK_Factor takes integer Card returns string local string CurrentCard_String if (Card == 11) then set CurrentCard_String = "J" else endif if ( Card == 12 ) then set CurrentCard_String = "Q" else endif if ( Card == 0 ) then set CurrentCard_String = "K" else endif if ( Card == 1 ) then set CurrentCard_String = "A" else endif set udg_TempString = CurrentCard_String set CurrentCard_String = null return udg_TempString endfunction |
| 04-04-2005, 02:27 PM | #3 |
Thank you very much for your help, I tried that top example but it didnt pass the compiler either but i didnt add the return "" at the end is that neccesary? dont reply if you dont want I'll just try it out. |
| 04-12-2005, 07:08 PM | #4 |
Obviously, a programmer would have figured out that this is an accessor method and has to have a return statement. Please learn programming before you make any more errors. |
