CInt()

Here you can post threads requesting help on the official POL Ultima Online Emulator Core 098.

Moderator: POL Developer

Post Reply
Polytropon
New User
Posts: 19
Joined: Wed Sep 15, 2010 9:47 pm

CInt()

Post by Polytropon »

Don´t know how to submit a bug, so I posted here.
It would be nice to understand why does this happen (just for curiosity).

Output of the CInt() function for some arbitrary strings that commence with zero:

CInt("01") = 1
CInt("02") = 2
CInt("03") = 3
CInt("04") = 4
CInt("05") = 5
CInt("06") = 6
CInt("07") = 7
CInt("08") = 0
CInt("09") = 0
CInt("010") = 8
CInt("011") = 9
(...)
CInt("018") = 1
CInt("019") = 1
CInt("020") = 16
(...)
CInt("028") = 2




The result is the same no matter how many zeroes are ahead.
Essentially, for 0-7 ones the result is "the number - (tens * 2) " and for 8-9 ones the result is the number of tens.
User avatar
Austin
Former Developer
Posts: 621
Joined: Wed Jan 25, 2006 2:30 am

Re: CInt()

Post by Austin »

If you start a string with 0x it is base-16
If you start a string with 0 it is base-8

What you are seeing is, Octal.

In one you have 028, but 8 cant be there, so it goes 02 and gives you 2
Polytropon
New User
Posts: 19
Joined: Wed Sep 15, 2010 9:47 pm

Re: CInt()

Post by Polytropon »

Haha, sorry for my ignorance.

I´ll keep it in mind in case I lose two fingers. :)
User avatar
Austin
Former Developer
Posts: 621
Joined: Wed Jan 25, 2006 2:30 am

Re: CInt()

Post by Austin »

If you have strings coming up, (this isnt the best way to do it, just the easiest off memory) and you need to remove leading 0s

Code: Select all

while ( text[0] == "0" )
   text[0] :="";
   Sleepms(2);
endwhile
Yukiko
Distro Developer
Posts: 2825
Joined: Thu Feb 02, 2006 1:41 pm
Location: San Antonio, Texas
Contact:

Re: CInt()

Post by Yukiko »

I wasn't aware of this either Austin. Is this the "standard" behaviour of CInt() in other languages? Either way it might be a good idea to update Racalac's eScript guide in the Documents section to indicate this?

Thanks.
User avatar
Austin
Former Developer
Posts: 621
Joined: Wed Jan 25, 2006 2:30 am

Re: CInt()

Post by Austin »

Its been the case since... forever. Yes, Rac's guide does need some updating so people know about the awesomeness that is _var_iter in a foreach loop.
Yukiko
Distro Developer
Posts: 2825
Joined: Thu Feb 02, 2006 1:41 pm
Location: San Antonio, Texas
Contact:

Re: CInt()

Post by Yukiko »

Hahahaha!
Oh yeah!
Post Reply