|
|
#1 |
|
Banned
![]() Join Date: Apr 2009
Location: England
Posts: 4,011
Reputation: 701
|
Hey, a simple question this time, I've never used this method while coding before so I'm not sure how to workaround this:
Say you have a function that returns 0 if it fails: pawn Code:
So I did the same thing with a string: pawn Code:
pawn Code:
So now I'm at a loss and don't know what to return at the end, I can't return nothing because I get a 'must return something' error. |
|
|
|
|
|
#2 |
|
Gangsta
![]() ![]() ![]() ![]() Join Date: Mar 2012
Location: Mi, USA
Posts: 938
Reputation: 144
|
maybe try return "\0";
i think that's the null char if that don't work return a 0 and check it with pawn Code:
|
|
|
|
|
|
#3 |
|
Banned
![]() Join Date: Apr 2009
Location: England
Posts: 4,011
Reputation: 701
|
I already said that returning anything like "this" crashes it, that's why "<NULL>" crashed it.
I can't return with 0 because I get a return type mismatch error because one return statement returns an array and the other just returns 0, which is an Integer. |
|
|
|
|
|
#4 |
|
Gangsta
![]() ![]() ![]() ![]() Join Date: Mar 2012
Location: Mi, USA
Posts: 938
Reputation: 144
|
i see what you mean
ima mess with this ill edit this post in a min. edit: the work around would be to pass the var byref to the function also. pawn Code:
set the vars value in the function using strcpy and return 1 for true and 0 for false. i think this is done with the @ char but dont quote me on this, or use the code below. HTH's |
|
|
|
|
|
#5 |
|
High-roller
![]() ![]() ![]() ![]() ![]() Join Date: Sep 2009
Posts: 2,126
Reputation: 174
|
i'm not sure you can do that.
however you can define a string, and format it, then you return the symbolic name of that string. that way you can correctly return a string, not directly. pawn Code:
|
|
|
|
|
|
#6 |
|
Gangsta
![]() ![]() ![]() ![]() Join Date: Jan 2008
Location: North Wales
Posts: 890
Reputation: 134
|
I'm kind of not sure what you want (with the return type), but if you want to return a string value, then yeah the PAWN compiler crashes with string literals. However, it doesn't seem to crash when you return a character array by reference:
pawn Code:
or .. pawn Code:
Both seem to compile fine for me. I'm not sure if the tag mismatch would be gone, because I don't know what tag you want - I assumed a character array. If you want to return a null string, return '\0' - it's the zero-termination character for strings. EDIT: Check admantis' code. |
|
|
|
|
|
#7 |
|
Godfather
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jan 2011
Location: England
Posts: 5,387
Reputation: 767
|
Return a space?
|
|
|
|
|
|
#8 |
|
Huge Clucker
![]() ![]() ![]() Join Date: Mar 2010
Location: Germany
Posts: 495
Reputation: 66
|
Make sure that you do return something like
pawn Code:
|
|
|
|
|
|
#9 |
|
Banned
![]() Join Date: Apr 2009
Location: England
Posts: 4,011
Reputation: 701
|
Thanks for the replies!
I finally went with creating a null temp string and returning that. I could have used a reference but that means not simply returning the value straight into a function or assignment, it means a new string variable, and that looks a bit more cluttered to me! Unfortunately I couldn't just create a 1 or 2 cell array as the return sizes had to match, so I had to create a completely useless 256 cell array! But oh well, problem solved! In case you're wondering it's for an update to my File Script, that will be posted tomorrow after a full bug test (link in my sig)
|
|
|
|
|
|
#10 |
|
The Finest
![]() ![]() ![]() ![]() ![]() Join Date: Apr 2009
Posts: 1,622
Reputation: 206
|
I don't understand why you'd need to return a string in pawn when you can just pass the string and return 1 or 0 depending on if it was changed or not
pawn Code:
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How can I set null a string? | _Zeus | Scripting Help | 2 | 21/02/2012 06:18 PM |
| Returning string. | Roko_foko | Help Archive | 13 | 15/07/2011 07:24 PM |
| Returning a string | maramizo | Help Archive | 5 | 14/04/2011 07:35 PM |
| String cuts when returning? | ziomal432 | Help Archive | 0 | 12/06/2010 07:57 PM |