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
4 registered members (TedMar, AndrewAMD, dr_panther, 1 invisible), 1,186 guests, and 4 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
Page 2 of 4 1 2 3 4
Re: multidimensional arrays as function arguments [Re: Kartoffel] #429377
09/11/13 20:07
09/11/13 20:07
Joined: Nov 2007
Posts: 318
Brasil, Paraná
NeoNeper Offline
Senior Member
NeoNeper  Offline
Senior Member

Joined: Nov 2007
Posts: 318
Brasil, Paraná
Now I understand where is the problem. and also can not solve


Please! Use easy words to be translated. because my English is not very good! Grateful.
_______________________________________________________
Re: multidimensional arrays as function arguments [Re: Kartoffel] #429378
09/11/13 20:08
09/11/13 20:08
Joined: Oct 2011
Posts: 1,082
Germany
C
Ch40zzC0d3r Offline
Serious User
Ch40zzC0d3r  Offline
Serious User
C

Joined: Oct 2011
Posts: 1,082
Germany
I dont see the problem Im doing it like this million of times in my code and it works perfectly.
Maybe I'll get some time to test it tomorrow.
An array is just a simple pointer, so double array = double pointer.

Re: multidimensional arrays as function arguments [Re: Kartoffel] #429381
09/11/13 20:36
09/11/13 20:36
Joined: Apr 2006
Posts: 159
Latvija
Arrovs Offline
Member
Arrovs  Offline
Member

Joined: Apr 2006
Posts: 159
Latvija
As im never at need after constant size arrays i can give you something like this:

Code:
#include <acknex.h>

//for new struct allocating
#define new(struktura) sys_malloc(sizeof(struktura))
#define newm(struktura, daudzums) sys_malloc(daudzums*sizeof(struktura))
//no matter which type as any pointer have same size except void* which will nto work here
typedef unsigned int* pointer;

//Array for any pointers you need
typedef struct Array
{
	pointer values;
	int length;
}Array;

//simple array control
Array* Array_inic(int length)
{
	Array* lok_array = new(Array);
	lok_array.values = newm(pointer, length);
	lok_array.length = length;
	return lok_array;
}

Array Array_del(Array* array)
{
	sys_free(array.values);
	sys_free(array);
}

void print_var(Array *input_array, unsigned int index_x, unsigned int index_y)
{
	Array* lok_array = (Array*)(input_array.values)[index_x];
	var* output_var = (lok_array.values)[index_y];
	
	printf("array[%.0f][%.0f] = %.0f", (double)index_x, (double)index_y, (double)*output_var);
}

void main()
{
	randomize();
	
	Array* vars = Array_inic(8);
	
	int i;
	int j;
	
	for(i = 0; i <= 8; i++)
	{
		(vars.values)[i] = Array_inic(8);
		for(j = 0; j <= 8; j++)
		{
			var* lok_var = new(var);
			*lok_var = random(100);
			Array* lok_array = (vars.values)[i];
			(lok_array.values)[j] = lok_var;
		}
	}	
	
	wait(1);
	
	print_var(vars, 4, 4);
}



As this struct is pointer array every value need to be pointer too, but you can define specific things as 2darray struct or even only function for that.

Overall i was amazed about 2d array not working through parameter.

Last edited by Arrovs; 09/11/13 20:44.

Arrovs once will publish game
Re: multidimensional arrays as function arguments [Re: Arrovs] #429384
09/11/13 20:58
09/11/13 20:58
Joined: Apr 2006
Posts: 159
Latvija
Arrovs Offline
Member
Arrovs  Offline
Member

Joined: Apr 2006
Posts: 159
Latvija
Although overall i use this method, but as im more often running into need after knowing how long is my arrays im started to make upper mentioned struct.

Code:
void*** masivs_2d(int garums, int augstums)
{
	//pirm&#257; dimensija
	void** masivs = jauni(void*, garums);
	//otr&#257;s dimensijas
	int lok_i = 0;
	for(lok_i = 0; lok_i < garums; lok_i++)
	{
		(masivs)[lok_i] = jauni(void*, augstums);
	}
	return (void***)masivs;
}

function masivs_2d_dzest(void*** masivs, garums)
{
	int lok_i = 0;
	for(lok_i = 0; lok_i < garums; lok_i += 1)
	{
		sys_free((masivs)[lok_i]);
	}
	sys_free(masivs);
	return NULL;
}

void print_var(void*** input_array, BOOL index_x, BOOL index_y)
{
	var* output_var = ((lok_array)[index_x])[index_y];
	
	printf("array[%.0f][%.0f] = %.0f", (double)index_x, (double)index_y, (double)*output_var);
}

function main()
{
vars* vars = masivs_2d(8, 8);
//fill it up, but still it is pointer array
print_var(vars, 4, 4)
}



Arrovs once will publish game
Re: multidimensional arrays as function arguments [Re: Arrovs] #429405
09/12/13 07:06
09/12/13 07:06
Joined: Mar 2011
Posts: 3,150
Budapest
sivan Offline
Expert
sivan  Offline
Expert

Joined: Mar 2011
Posts: 3,150
Budapest
your 2nd code in the 1st post contained i++ instead of j++ this is the reason of the error message


Free world editor for 3D Gamestudio: MapBuilder Editor
Re: multidimensional arrays as function arguments [Re: sivan] #429410
09/12/13 09:35
09/12/13 09:35
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline OP
Expert
Kartoffel  Offline OP
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
@sivan: yes and no.

it's not the reason for the 'dimension of array'-error, but if it worked the i++ would have caused a script error. grin


POTATO-MAN saves the day! - Random
Re: multidimensional arrays as function arguments [Re: Kartoffel] #429419
09/12/13 11:10
09/12/13 11:10
Joined: Mar 2012
Posts: 927
cyberspace
W
Wjbender Offline
User
Wjbender  Offline
User
W

Joined: Mar 2012
Posts: 927
cyberspace
your code works 100% when i tested it (except i changed your i++) but with or without i it i had
no errors even after passing addres of vars or ommiting the pointer it still worked fine .

what error are you receiving exactly ?

i am using a8 free and no errors whatsoever...

im guessing you receive a compiler error ?

m


Compulsive compiler
Re: multidimensional arrays as function arguments [Re: Wjbender] #429422
09/12/13 11:17
09/12/13 11:17
Joined: Nov 2007
Posts: 318
Brasil, Paraná
NeoNeper Offline
Senior Member
NeoNeper  Offline
Senior Member

Joined: Nov 2007
Posts: 318
Brasil, Paraná
Code:
#include <acknex.h>


var vars[8][8];

void print_var(var **input_array, unsigned int index_x, unsigned int index_y)
{
	var output_var = input_array[index_x][index_y];
	
	printf("array[%.0f][%.0f] = %.0f", (double)index_x, (double)index_y, (double)output_var);
}

void main()
{
	
	
	int i;
	int j;
	
	for(i = 0; i <= 8; i++)
	for(j = 0; j <= 8; j++)
	{
		vars[i][j] = 100;
	}
	
	
	wait(1);
	
	print_var(vars, 8, 8);

}



NOOO WOOORK.

The problem is to pass as parameter the address of a variable dimensional
Look:
void print_var(var **input_array, unsigned int index_x, unsigned int index_y)
{
var output_var = input_array[index_x][index_y];
...


This is where the problem is!
How can be indicated by parameters the address of a variable BI-Dimensional

Last edited by NeoNeper; 09/12/13 11:23.

Please! Use easy words to be translated. because my English is not very good! Grateful.
_______________________________________________________
Re: multidimensional arrays as function arguments [Re: Wjbender] #429426
09/12/13 11:33
09/12/13 11:33
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline OP
Expert
Kartoffel  Offline OP
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Originally Posted By: Wjbender
your code works 100% when i tested it (except i changed your i++) but with or without i it i had
no errors even after passing addres of vars or ommiting the pointer it still worked fine .

what error are you receiving exactly ?

i am using a8 free and no errors whatsoever...

im guessing you receive a compiler error ?

m

I'm using A8 Pro (before you ask: I know, pirated versions contain lots of bugs but mine is legal)

thats the code and compiler error:


@NeoNeper: the same as above is happening ;_;

I guess I'll have to try to reinstall 3DGS smirk


POTATO-MAN saves the day! - Random
Re: multidimensional arrays as function arguments [Re: Kartoffel] #429429
09/12/13 11:40
09/12/13 11:40
Joined: Nov 2007
Posts: 318
Brasil, Paraná
NeoNeper Offline
Senior Member
NeoNeper  Offline
Senior Member

Joined: Nov 2007
Posts: 318
Brasil, Paraná
The problem is not the 3DGS, as you and I reported above, this problem really exists ..

Is it not the case that developers ask?


Please! Use easy words to be translated. because my English is not very good! Grateful.
_______________________________________________________
Page 2 of 4 1 2 3 4

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