Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (vicknick, AndrewAMD), 1,292 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
adding additional numbers to an existing var #449811
03/31/15 21:41
03/31/15 21:41
Joined: Aug 2005
Posts: 199
houston
S
seneca Offline OP
Member
seneca  Offline OP
Member
S

Joined: Aug 2005
Posts: 199
houston
Like the subject line reads, I've been beating my head against the wall on how to program adding an additional number to a variable of numbers that already exist. what I mean is if I have a variable called set_numbers:

var set_numbers = 10;

now I want to add the numbers 23 to the back end of it, so that now set_number is = 1023, but the numbers being added is off the fly and maybe totally random.

I've tried using an array. even tried str_for_num and str_to_num, inkey and some other things to stack the numbers behind each other. I know there must be a way, but I just can't seem to figure it out. any help would be appreciated. Thanks.


a8 commercial
Re: adding additional numbers to an existing var [Re: seneca] #449813
03/31/15 21:51
03/31/15 21:51
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
I would suggest to use string for adding the numbers, then convert it to variable.

Something like (not tested):
Code:
STRING* setNumStr = "10";

void test(){
     str_cat(setNumStr, "23");
     var number = str_to_num(setNumStr);
}

Maybe it's no the fastest way to do it, but it should work laugh

Edit: check str_cat_num too!

Best regards!

Last edited by 3run; 03/31/15 22:09. Reason: added str_cat_num

Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: adding additional numbers to an existing var [Re: 3run] #449830
04/01/15 08:18
04/01/15 08:18
Joined: Jan 2006
Posts: 968
EpsiloN Offline
User
EpsiloN  Offline
User

Joined: Jan 2006
Posts: 968
And, if you need the original number to be a var, put it in a var and use str_for_num( string , var )
This will convert your var to string, and then use 3run's example to add to the string and convert back to var...

If you want to use numbers only (no strings) you could multiply the first number by the next round big of the second number, in your example:
10 * 100 = 1000 + 23 = 1023.
Another example:
432 and 569
432 * 1000 = 432000 + 569 = 432569...


Extensive Multiplayer tutorial:
http://mesetts.com/index.php?page=201
Re: adding additional numbers to an existing var [Re: EpsiloN] #449832
04/01/15 10:37
04/01/15 10:37
Joined: Aug 2005
Posts: 199
houston
S
seneca Offline OP
Member
seneca  Offline OP
Member
S

Joined: Aug 2005
Posts: 199
houston
Thanks, you guys for the replies. I will test it out.


a8 commercial
Re: adding additional numbers to an existing var [Re: seneca] #449840
04/01/15 12:55
04/01/15 12:55
Joined: Aug 2005
Posts: 199
houston
S
seneca Offline OP
Member
seneca  Offline OP
Member
S

Joined: Aug 2005
Posts: 199
houston
Worked like a dream. It's amazing that I didn't think of it before. Thanks you guys for your help.


a8 commercial
Re: adding additional numbers to an existing var [Re: seneca] #449901
04/02/15 08:36
04/02/15 08:36
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
A solution with no strings:

Code:
int int_glue ( int n1, int n2 )
{
	int n2b = n2;
	for ( ; n2b>0; n2b/=10 )
		n1 *= 10;
	n1 += n2;
	return n1;
}

void main ()
{
	int a = 12345;
	int b = 67890;
	int c = int_glue ( a, b );
	error ( str_for_int(NULL, c) );
}



Salud!

Re: adding additional numbers to an existing var [Re: txesmi] #449902
04/02/15 08:41
04/02/15 08:41
Joined: May 2008
Posts: 2,113
NRW/Germany
alibaba Offline
Expert
alibaba  Offline
Expert

Joined: May 2008
Posts: 2,113
NRW/Germany
Nice solution txesmi!


Professional Edition
A8.47.1
--------------------
http://www.yueklet.de
Re: adding additional numbers to an existing var [Re: alibaba] #449903
04/02/15 09:02
04/02/15 09:02
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
txesmi is a math master! grin great solution!

Best regards laugh


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: adding additional numbers to an existing var [Re: 3run] #449906
04/02/15 09:58
04/02/15 09:58
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
grin
We have to admit that is not that much. But let's wet the hell; I like my newly acquired straw throne.

Re: adding additional numbers to an existing var [Re: txesmi] #449909
04/02/15 10:12
04/02/15 10:12
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
Originally Posted By: txesmi
grin
We have to admit that is not that much. But let's wet the hell; I like my newly acquired straw throne.
grin grin grin


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1