![]() |
Function arguments and numbers - Printable Version +- SphereCommunity (https://forum.spherecommunity.net) +-- Forum: Sphere 0.56d (/Forum-Sphere-0-56d) +--- Forum: Script Help (/Forum-Script-Help) +--- Thread: Function arguments and numbers (/Thread-Function-arguments-and-numbers) Pages: 1 2 |
Function arguments and numbers - karma - 05-04-2014 05:24 AM Simple but tedious problem: i pass to a function this arguments: 02, 2. Those are two numbers, first one hex, second decimal, but still numbers. I want them to be treated as chars, because in this function <argn1> and <argn2>, or <argv[0]> and <argv[1]> show the number in its hex notation, or 02 and 02. Basically i want that <argv[0]> is 02 and <argv[1]> is 2, is it possible? RE: Function arguments and numbers - Alaric - 05-04-2014 05:39 AM <argv[0]> <dargv[1]> This? RE: Function arguments and numbers - karma - 05-04-2014 05:52 AM Nope, because the function does not know if i'm passing a number, or if i want always the number to be printed in his hex or decimal notation. I need to print out the number, or better the argument, as i passed it, like it was a string and not a number. RE: Function arguments and numbers - Feeh - 05-04-2014 06:27 AM Sorry but I think I did not understand what you mean... What Alaric said makes sense [function f_test1] f_test2 02 3 [function f_test2] serv.log <argn1> -- <dargn1>//will output 02 -- 2 serv.log <argn2> -- <dargn2>//will output 03 -- 3 Anything that starts with a '0' and contains ONLY 0~9 and/or a~f is treated as hex Anything that contains ONLY 0~9 is treated as decimal hex and decimal are both numbers with different notation but same values and range. AFAIK sphere prefers to always store them as number, unless internally pointed to treat them as decimal Anything else is a string Your script logic must know what to do. If you may pass a number AND string to the same function, it must know what to do http://wiki.sphere.torfo.org/index.php/Chapter_10#String_Functions Try using <ARGS> then STRARG/STREAT it for your needs You can force it to be treated as string by adding a non-number element on it f_myfunc :2 :02 then remove the first char RE: Function arguments and numbers - Alaric - 05-04-2014 06:47 AM and if you send it to the function like this? tag.number=2 myfunction "<tag.number>" [myfunction] <argv[0]> = 2 or "2"? Its weird what you do. you have to know if you pass hex or dec in the function. Or use the separation prolly. But still... RE: Function arguments and numbers - karma - 05-04-2014 07:51 AM Let me explain better. I am testing the function i posted here http://forum.spherecommunity.net/Thread-Custom-sysmessage-function. Calling UTEXT 0,0,0,0,test will show "test". Calling UTEXT 0,0,0,0,0c will show "0c". Calling UTEXT 0,0,0,0,12 will show "oc". This because of the automatic typization of arguments and variables in spherescript. <ARGV[4]> is treated as a string if i send "test", but as a number if i send "0c", or "12". The ideal behavior would be to treat all arguments as strings or, in the case, single chars. Thus, in the "12" case, a SAY <ARGV[4]> will show 0c, not 12, because numbers are automatically parsed in hex. I cannot EVAL or HVAL <ARGV[4]> a priori, because i can use the same function to display strings, decimal or hexadecimal numbers, or whatever. I do know what i'll pass, but i'm trying to use this function for general purposes. I can't use ARGS and STRARG/STREAT, because i separate arguments with commas, not with spaces. RE: Function arguments and numbers - Alaric - 05-04-2014 09:20 AM Code: [function ff] Code: [function ff] Its not chaging dec to hex. I've got some nightly 56c 3 months old. Separating number and chars is easy, just checking <isnumber ...> and then you can eval or not. But the hex/dec is weird, check it again please. The function itself isn't probably changing number to hex. And did you try the above said? fff 0,"0c" Again gives me 0,0c in console. RE: Function arguments and numbers - karma - 05-04-2014 09:41 AM Okay, it was my fault. <ARGV[4]> IS 0c if i pass 0c, and 12 if i pass 12. The trouble in the function was that i did LOCAL._TEXT=<ARGV[4]>, so that this local is now a number-type variable. So doing SERV.LOG <ARGV[4]> is 12, but SERV.LOG <LOCAL._TEXT> is 0c. I'll post a newer and corrected version of the function in the other section, thanks everybody! Re: Function arguments and numbers - Extreme - 05-04-2014 09:49 AM <hval > ? RE: Function arguments and numbers - karma - 05-04-2014 09:58 AM I cannot HVAL or EVAL the argument, because it might be text, or a number i want in a notation and not in another. It's like with SAY: to correct this "problem" the SAY function can't HVAL the argument, because i can use SAY for everything (SAY hello, SAY 12, SAY 012af). Anyways, the corrected and updated function is here: http://forum.spherecommunity.net/Thread-Custom-speech-function |