The following warnings occurred:
Warning [2] Use of undefined constant SAPI_NAME - assumed 'SAPI_NAME' (this will throw an Error in a future version of PHP) - Line: 3388 - File: inc/functions.php PHP 7.4.33-nmm7 (Linux)
File Line Function
/inc/functions.php 3388 errorHandler->error
/showthread.php 116 build_archive_link
Warning [2] Use of undefined constant IN_ARCHIVE - assumed 'IN_ARCHIVE' (this will throw an Error in a future version of PHP) - Line: 3331 - File: inc/functions.php PHP 7.4.33-nmm7 (Linux)
File Line Function
/inc/functions.php 3331 errorHandler->error
/inc/functions.php 3324 build_forum_breadcrumb
/showthread.php 195 build_forum_breadcrumb
Warning [2] Use of undefined constant IN_ARCHIVE - assumed 'IN_ARCHIVE' (this will throw an Error in a future version of PHP) - Line: 3331 - File: inc/functions.php PHP 7.4.33-nmm7 (Linux)
File Line Function
/inc/functions.php 3331 errorHandler->error
/showthread.php 195 build_forum_breadcrumb






Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Function arguments and numbers
Author Message
karma
Moderator
****

Posts: 178
Likes Given: 17
Likes Received: 32 in 29 posts
Joined: Jul 2012
Reputation: 3



Post: #1
Function arguments and numbers
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?
(This post was last modified: 05-04-2014 05:24 AM by karma.)
05-04-2014 05:24 AM
Find all posts by this user Like Post Quote this message in a reply
Alaric
Journeyman
*

Posts: 227
Likes Given: 7
Likes Received: 9 in 4 posts
Joined: Oct 2012
Reputation: 7



Post: #2
RE: Function arguments and numbers
<argv[0]>
<dargv[1]>

This?
(This post was last modified: 05-04-2014 05:39 AM by Alaric.)
05-04-2014 05:39 AM
Find all posts by this user Like Post Quote this message in a reply
karma
Moderator
****

Posts: 178
Likes Given: 17
Likes Received: 32 in 29 posts
Joined: Jul 2012
Reputation: 3



Post: #3
RE: Function arguments and numbers
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.
05-04-2014 05:52 AM
Find all posts by this user Like Post Quote this message in a reply
Feeh
Sphere Developer
*****

Posts: 156
Likes Given: 6
Likes Received: 40 in 29 posts
Joined: Sep 2012
Reputation: 4



Post: #4
RE: Function arguments and numbers
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/C..._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

Feeh/Epila - Nightly releases / SphereWiki / Github Issues / Sphere's GitHub
(This post was last modified: 05-04-2014 06:29 AM by Feeh.)
05-04-2014 06:27 AM
Find all posts by this user Like Post Quote this message in a reply
Alaric
Journeyman
*

Posts: 227
Likes Given: 7
Likes Received: 9 in 4 posts
Joined: Oct 2012
Reputation: 7



Post: #5
RE: Function arguments and numbers
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...
(This post was last modified: 05-04-2014 06:51 AM by Alaric.)
05-04-2014 06:47 AM
Find all posts by this user Like Post Quote this message in a reply
karma
Moderator
****

Posts: 178
Likes Given: 17
Likes Received: 32 in 29 posts
Joined: Jul 2012
Reputation: 3



Post: #6
RE: Function arguments and numbers
Let me explain better.
I am testing the function i posted here http://forum.spherecommunity.net/Thread-...-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.
(This post was last modified: 05-04-2014 07:53 AM by karma.)
05-04-2014 07:51 AM
Find all posts by this user Like Post Quote this message in a reply
Alaric
Journeyman
*

Posts: 227
Likes Given: 7
Likes Received: 9 in 4 posts
Joined: Oct 2012
Reputation: 7



Post: #7
RE: Function arguments and numbers
Code:
[function ff]
fff 0,0c

[function fff]
serv.log <argv[0]>,<argv[1]>
LOG: 01:19:(custom_functions_test.scp,16)0,0c


Code:
[function ff]
fff 0,12

[function fff]
serv.log <argv[0]>,<argv[1]>
LOG: 01:20:(custom_functions_test.scp,16)0,12


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.
(This post was last modified: 05-04-2014 09:27 AM by Alaric.)
05-04-2014 09:20 AM
Find all posts by this user Like Post Quote this message in a reply
karma
Moderator
****

Posts: 178
Likes Given: 17
Likes Received: 32 in 29 posts
Joined: Jul 2012
Reputation: 3



Post: #8
RE: Function arguments and numbers
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!
05-04-2014 09:41 AM
Find all posts by this user Like Post Quote this message in a reply
Extreme
Grandmaster Poster
***

Posts: 1,141
Likes Given: 217
Likes Received: 90 in 77 posts
Joined: May 2012
Reputation: 20

SphereCommunity

Post: #9
Re: Function arguments and numbers
<hval >
?

STEPS BEFORE CREATE A THREAD
- Check the revisions log;
- Use the search button and use the keywords of your problem;
- Check the WIKI;
- Create a thread.
05-04-2014 09:49 AM
Find all posts by this user Like Post Quote this message in a reply
karma
Moderator
****

Posts: 178
Likes Given: 17
Likes Received: 32 in 29 posts
Joined: Jul 2012
Reputation: 3



Post: #10
RE: Function arguments and numbers
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-...h-function
05-04-2014 09:58 AM
Find all posts by this user Like Post Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 5 Guest(s)