-
Long Int
Hey guys,
I have a problem with big numbers inside gsc.
I have a loong number in a string. I can extract it but datatype still seems to be a string, so I can't use it for calculations.
I casted the string using (int) but the max value of a normal integer is exceeded.
Is there a possibility to use a long int for example? Float seems to have same limitations as int..
Thanks for answers!
-
Cod2 does not support anything above 32bit data types, so you have to store it either in raw memory, making calculations harder, or in a string, making calculations near impossible.
What are you trying to achieve with it?
-
The number is the score of a player. The first player is no reaching the limits.. I have something to do :/
How could I store it in raw memory?
It's for UO anyway
-
How is a player ever reaching such a score of 2 BILLION?
Given that you're generous and give 100 xp/kill, the player has to get 20 million kills. This means that, given 1 kill per second, he'd have to continuously keep killing people at said rate for over 5000 hour or over 200 days.
If you're giving more than 100 xp/kill, i'd advise you to either lower that, or just add a multiplier to the score (kill = 1000xp, store xp in multiples of 1000)
-
Or, if you are masochistic, add a binding of a big number library to gsc:
https://gmplib.org/
Code:
gcc -o add_example add_example.c -lgmp -lm
Code:
#include <stdio.h> /* for printf */
#include <gmp.h>
int main(int argc, char *argv[])
{
mpz_t a, b; /* working numbers */
if (argc<3)
{ /* not enough words */
printf("Please supply two numbers to add.\n");
return 1;
}
mpz_init_set_str (a, argv[1], 10); /* Assume decimal integers */
mpz_init_set_str (b, argv[2], 10); /* Assume decimal integers */
mpz_add (a, a, b); /* a=a+b */
printf("%s + %s => %s\n", argv[1], argv[2], mpz_get_str (NULL, 10, a));
return 0;
}
-
How can I add a new data type to gsc then?
-
Oh, you wanna add big int types to the scripting engine instead of a simple binding of a big int library?
Then you just gotta reverse engineer and fit the bison/flex scanner/parser/opcode generator/interpreter.
As easy introduction I suggest this little toy language: http://www.peroxide.dk/tuts_scr.shtml
-
How you reach 2,147,483,647 I don't know but from memory a friend of mine bypassed the 32bit int limit by using strings and using B for Billion, T for Trillion etc.
-
I used strings now :) Was the easiest method. To calculate the strings I use a helper function in c++
Thanks for your tipps guys