Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (Nymphodora, AndrewAMD, TipmyPip, Quad, Imhotep), 847 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
random(var x) - malfunction #301219
12/09/09 01:24
12/09/09 01:24
Joined: Jun 2006
Posts: 214
Germany, NRW
T
TheThinker Offline OP
Member
TheThinker  Offline OP
Member
T

Joined: Jun 2006
Posts: 214
Germany, NRW
Can you explain this behavior of "random(var x)"

Here my function:

Code:
void createPrePipe()
{
	int i;
	random(2);//<-------------------RANDOM DOESN'T CRASH
	for(i=0; i<5; i++)
	{
		zero(preview[i]);
		preview[i].cell = ent_create("cell.mdl", vector(-160, 0, 928), NULL);
		preview[i].pipes[0] = ent_create("pHor.mdl", vector(-160, -32, 928), NULL);
		preview[i].pipes[1] = ent_create("pVert.mdl", vector(-160, -32, 928), NULL);
		preview[i].pipes[2] = ent_create("pCornerTopLeft.mdl", vector(-160, -32, 928), NULL);
		preview[i].pipes[3] = ent_create("pCornerLeftBottom.mdl", vector(-160, -32, 928), NULL);
		preview[i].pipes[4] = ent_create("pCornerBottomRight.mdl", vector(-160, -32, 928), NULL);
		preview[i].pipes[5] = ent_create("pCornerRightTop.mdl", vector(-160, -32, 928), NULL);
		preview[i].pipes[6] = ent_create("pCross.mdl", vector(-160, -32, 928), NULL);
		set(preview[i].pipes[0], INVISIBLE);
		set(preview[i].pipes[1], INVISIBLE);
		set(preview[i].pipes[2], INVISIBLE);
		set(preview[i].pipes[3], INVISIBLE);
		set(preview[i].pipes[4], INVISIBLE);
		set(preview[i].pipes[5], INVISIBLE);
		set(preview[i].pipes[6], INVISIBLE);
		set(preview[i].cell, INVISIBLE);
	}
	random(2);//<-------------------RANDOM DOESN'T CRASH
	preview[0].next = NULL;
	preview[1].next = &preview[0];
	preview[2].next = &preview[1];
	preview[3].next = &preview[2];
	preview[4].next = &preview[3];
	preview[5].next = &preview[4];
	random(2);//<-------------------RANDOM DOESN'T CRASH
	
	preview[0].before = &preview[1];
	preview[1].before = &preview[2];
	preview[2].before = &preview[3];
	preview[3].before = &preview[4];
	preview[4].before = &preview[5];
	preview[5].before = NULL;
	random(2);//<-------------------RANDOM CRASHS !!!!!!!!!!!!!! ------------>
	random(2);
	STRING* deb = "";
	
	
	
	wait(-1);
	
	preMove(&preview[0]);
	
	wait(-0.5);
	
	preMove(&preview[1]);
	
	wait(-0.5);
	
	preMove(&preview[2]);
}



I don't understand this behaviour. The rest of the code is ok, but I need random after the creation of this models, to randomize theire visibility.

Last edited by TheThinker; 12/09/09 01:25.
Re: random(var x) - malfunction [Re: TheThinker] #301222
12/09/09 01:52
12/09/09 01:52
Joined: Jul 2008
Posts: 553
Singapore
delinkx Offline
User
delinkx  Offline
User

Joined: Jul 2008
Posts: 553
Singapore
random(x) returns a value. u are just running the function. it wont serve the purpose. u need to assign it to a variable:

myVar = random(2);


A7 commercial Team / VC++ 2008 Pro
homepage | twitter | facebook
Re: random(var x) - malfunction [Re: delinkx] #301224
12/09/09 02:02
12/09/09 02:02
Joined: Jun 2006
Posts: 214
Germany, NRW
T
TheThinker Offline OP
Member
TheThinker  Offline OP
Member
T

Joined: Jun 2006
Posts: 214
Germany, NRW
Thank you for your quick answer.
But I am very sure, that you can use value-returning functions withour setting the returnvalue to a var.

But I've tested this too "var x; x = random(2);"

The strange thing is, that it will run before and after my "for", and between the pointer settings ... but not after I set the whole pointerlist.

Re: random(var x) - malfunction [Re: TheThinker] #301226
12/09/09 02:48
12/09/09 02:48
Joined: Jul 2008
Posts: 553
Singapore
delinkx Offline
User
delinkx  Offline
User

Joined: Jul 2008
Posts: 553
Singapore
yes u can run the function. but wats the point running it if u not using the output ?

wat is the crash error given ?


A7 commercial Team / VC++ 2008 Pro
homepage | twitter | facebook
Re: random(var x) - malfunction [Re: delinkx] #301227
12/09/09 02:58
12/09/09 02:58
Joined: Jun 2006
Posts: 214
Germany, NRW
T
TheThinker Offline OP
Member
TheThinker  Offline OP
Member
T

Joined: Jun 2006
Posts: 214
Germany, NRW
I am running the function only for debugging reasons. I can exclude other errors with this mothod.
So I know that the crash must happen in the random-function itself.

The crash error is that:

"Crash in createPipes" ---(or other function name.
It depends not on the function. I have tested it with a lot of easier functions, but the results are only confusing.

Re: random(var x) - malfunction [Re: delinkx] #301228
12/09/09 03:12
12/09/09 03:12
Joined: Jul 2008
Posts: 553
Singapore
delinkx Offline
User
delinkx  Offline
User

Joined: Jul 2008
Posts: 553
Singapore
i tested ur code. and i dont get any crash. here is the sample i used:

Code:
typedef struct
{
	ENTITY* cell;
	ENTITY* pipes[10];
	var next;
	var before;
}previewstruct;

previewstruct preview[10];

void preMove(var *test)
{
	
}

void createPrePipe()
{
	int i;
	random(2);//<-------------------RANDOM DOESN'T CRASH
	for(i=0; i<5; i++)
	{
		zero(preview[i]);
		preview[i].cell = ent_create("cell.mdl", vector(-160, 0, 928), NULL);
		preview[i].pipes[0] = ent_create("pHor.mdl", vector(-160, -32, 928), NULL);
		preview[i].pipes[1] = ent_create("pVert.mdl", vector(-160, -32, 928), NULL);
		preview[i].pipes[2] = ent_create("pCornerTopLeft.mdl", vector(-160, -32, 928), NULL);
		preview[i].pipes[3] = ent_create("pCornerLeftBottom.mdl", vector(-160, -32, 928), NULL);
		preview[i].pipes[4] = ent_create("pCornerBottomRight.mdl", vector(-160, -32, 928), NULL);
		preview[i].pipes[5] = ent_create("pCornerRightTop.mdl", vector(-160, -32, 928), NULL);
		preview[i].pipes[6] = ent_create("pCross.mdl", vector(-160, -32, 928), NULL);
		set(preview[i].pipes[0], INVISIBLE);
		set(preview[i].pipes[1], INVISIBLE);
		set(preview[i].pipes[2], INVISIBLE);
		set(preview[i].pipes[3], INVISIBLE);
		set(preview[i].pipes[4], INVISIBLE);
		set(preview[i].pipes[5], INVISIBLE);
		set(preview[i].pipes[6], INVISIBLE);
		set(preview[i].cell, INVISIBLE);
	}
	random(2);//<-------------------RANDOM DOESN'T CRASH
	preview[0].next = NULL;
	preview[1].next = &preview[0];
	preview[2].next = &preview[1];
	preview[3].next = &preview[2];
	preview[4].next = &preview[3];
	preview[5].next = &preview[4];
	random(2);//<-------------------RANDOM DOESN'T CRASH
	
	preview[0].before = &preview[1];
	preview[1].before = &preview[2];
	preview[2].before = &preview[3];
	preview[3].before = &preview[4];
	preview[4].before = &preview[5];
	preview[5].before = NULL;
	random(2);//<-------------------RANDOM CRASHS !!!!!!!!!!!!!! ------------>
	random(2);
	STRING* deb = "";
	
	
	
	wait(-1);
	
	preMove(&preview[0]);
	
	wait(-0.5);
	
	preMove(&preview[1]);
	
	wait(-0.5);
	
	preMove(&preview[2]);
	

}




A7 commercial Team / VC++ 2008 Pro
homepage | twitter | facebook
Re: random(var x) - malfunction [Re: delinkx] #301229
12/09/09 03:14
12/09/09 03:14
Joined: Jul 2008
Posts: 553
Singapore
delinkx Offline
User
delinkx  Offline
User

Joined: Jul 2008
Posts: 553
Singapore
the crash u mentioning is an EMPTY pointer crash. not the random function crash.


A7 commercial Team / VC++ 2008 Pro
homepage | twitter | facebook
Re: random(var x) - malfunction [Re: delinkx] #301230
12/09/09 03:28
12/09/09 03:28
Joined: Jun 2006
Posts: 214
Germany, NRW
T
TheThinker Offline OP
Member
TheThinker  Offline OP
Member
T

Joined: Jun 2006
Posts: 214
Germany, NRW
No, it is the random function. The pointer definitions are right in every case I,ve tested them.
Only if I add the random-function, the engine crashs.

This function is called from an event_function:

Code:
void resetPrePipe()
{
  var rnd;
  random(2);
}



same problem here.
Updated version of the whole script...:

Code:
///////////////////////////////
#include <acknex.h>
#include <default.c>

///////////////////////////////

typedef struct PREPIPE
{
	ENTITY* cell;
	ENTITY* pipes[7];
	var futureZ;
	var rnd;
	struct PREPIPE* next;
	struct PREPIPE* before;
}PREPIPE;

typedef struct PIPE
{
	ENTITY* cell;
	ENTITY* pipes[11];
	var active;
	struct PIPE* slots[4];
	int connected;
}PIPE;

void initLevel();
void createPrePipe();
void preMove(PREPIPE* pre);
void eventClick();
void resetPrePipe();

ENTITY* border;
ENTITY* borderPrev;
ENTITY* arrowsPrev;

PREPIPE preview[5];
PIPE board[10][7];
PREPIPE* active;
PREPIPE* last;

void main()
{
	video_switch(8, 32, 8);
	wait(1);
	level_load("");
	wait(1);
	initLevel();
	wait(-1);
	createPrePipe();
}

void initLevel()
{
	int x; int y; int i;
	VECTOR ta;
	
	mouse_mode = 4;
	mouse_pointer = 2;
	mouse_sync = 1;
	mouse_range = 8000;
	sun_angle.pan = 275;
	sun_angle.tilt = 60;
	
	camera.pan = 90;
	camera.y = -2048;
	camera.x = 576;
	camera.z = 384;
	set(camera, ISOMETRIC);
	camera.arc = 80;
	
	border = ent_create("border.mdl", nullvector, NULL);
	borderPrev = ent_create("borderPrev.mdl", nullvector, NULL);
	arrowsPrev = ent_create("arrowsPrev.mdl", nullvector, NULL);
	
	for(x=0; x<10; x++)
	{
		for(y=0; y<7; y++)
		{
			zero(board[x][y]);
			vec_set(ta, vector(x * 128, 0, y * 128));
			board[x][y].cell = ent_create("cell.mdl", ta, NULL);
			board[x][y].cell.emask |= ENABLE_CLICK;
			board[x][y].cell.event = eventClick;
			board[x][y].cell.skill1 = x;
			board[x][y].cell.skill2 = y;
			board[x][y].cell.skill3 = 0;
			board[x][y].pipes[0] = ent_create("pStartRight.mdl", ta, NULL);
			board[x][y].pipes[1] = ent_create("pStartTop.mdl", ta, NULL);
			board[x][y].pipes[2] = ent_create("pStartLeft.mdl", ta, NULL);
			board[x][y].pipes[3] = ent_create("pStartBottom.mdl", ta, NULL);
			board[x][y].pipes[4] = ent_create("pHor.mdl", ta, NULL);
			board[x][y].pipes[5] = ent_create("pVert.mdl", ta, NULL);
			board[x][y].pipes[6] = ent_create("pCornerTopLeft.mdl", ta, NULL);
			board[x][y].pipes[7] = ent_create("pCornerLeftBottom.mdl", ta, NULL);
			board[x][y].pipes[8] = ent_create("pCornerBottomRight.mdl", ta, NULL);
			board[x][y].pipes[9] = ent_create("pCornerRightTop.mdl", ta, NULL);
			board[x][y].pipes[10] = ent_create("pCross.mdl", ta, NULL);
			for(i=0; i<11; i++)
			{
				set(board[x][y].pipes[i], INVISIBLE);
			}
		}
	}
	
	x = integer(random(10));
	y = integer(random(7));
	i = integer(random(4));
	reset(board[x][y].pipes[i], INVISIBLE);
	board[x][y].cell.skill3 = 1;
}

void preMove(PREPIPE* pre)
{
	int i;
	var acc = 4;
	var fall = 0;
	
	reset(pre.cell, INVISIBLE);
	reset(pre.pipes[pre.rnd], INVISIBLE);
	if(pre.next == NULL){pre.futureZ = 256;}else{pre.futureZ = pre.next.futureZ + 128;}
	
	while(pre.cell.z > pre.futureZ)
	{
		accelerate(fall, acc, 0);
		pre.cell.z -= fall * time_step;
		for(i=0; i<7; i++)
		{
			pre.pipes[i].z -= fall * time_step;
		}
		wait(1);
	}
	pre.cell.z = pre.futureZ;
}

void createPrePipe()
{
	int i; int l;
	var rnd = 0;
	
	for(i=0; i<5; i++)
	{
		zero(preview[i]);
		preview[i].cell = ent_create("cell.mdl", vector(-160, 0, 928), NULL);
		preview[i].pipes[0] = ent_create("pHor.mdl", vector(-160, -32, 928), NULL);
		preview[i].pipes[1] = ent_create("pVert.mdl", vector(-160, -32, 928), NULL);
		preview[i].pipes[2] = ent_create("pCornerTopLeft.mdl", vector(-160, -32, 928), NULL);
		preview[i].pipes[3] = ent_create("pCornerLeftBottom.mdl", vector(-160, -32, 928), NULL);
		preview[i].pipes[4] = ent_create("pCornerBottomRight.mdl", vector(-160, -32, 928), NULL);
		preview[i].pipes[5] = ent_create("pCornerRightTop.mdl", vector(-160, -32, 928), NULL);
		preview[i].pipes[6] = ent_create("pCross.mdl", vector(-160, -32, 928), NULL);
		for(l=0; l<7; l++)
		{
			set(preview[i].pipes[l], INVISIBLE);
		}
		set(preview[i].cell, INVISIBLE);
		rnd = integer(random(7));
		preview[i].rnd = rnd;
	}
	
	preview[0].next = NULL;
	for(i=1; i<6; i++){preview[i].next = &preview[i -1];}
	
	for(i=0; i<5; i++){preview[i].before = &preview[i + 1];}
	preview[5].before = NULL;
	
	for(i=0; i<5; i++)
	{
		wait(-0.5);
		preMove(&preview[i]);
	}
	
	active = &preview[0];
	last = &preview[5];
}

void eventClick()
{
	if(my.skill3 == 0)
	{
		int x = my.skill1;
		int y = my.skill2;
		
		reset(board[x][y].pipes[active.rnd + 4], INVISIBLE);
		my.skill3 = 1;
		resetPrePipe();
	}
}

void resetPrePipe()
{
	int i;
	PREPIPE* tmp;
	
	wait(1);
	//set(active.pipes[active.rnd], INVISIBLE);
	//set(active.cell, INVISIBLE);
	//active.rnd = integer(random(7));
//	vec_set(active.cell.x, vector(-160, 0, 928));
//	for(i=0; i<7; i++)
//	{
//		vec_set(active.pipes[i].x, vector(-160, -32, 928));
//	}
	
//	tmp = active.before;
//	active.next = last;
//	tmp.next = NULL;
//	last.before = active;
//	last = active;
//	active = tmp;
//	
//	wait(-0.5);
//	preMove(tmp);
//	for(i=0; i<4; i++)
//	{
//		if(tmp.before != NULL)
//		{
//			wait(-0.5);
//			tmp = tmp.before;
//			preMove(tmp);
//		}
//		else
//		{
//			break;
//		}	
//	}
}



The first random I use (a bit tricky here) runs without problems (in createPrePipes)

The game is running ...

But if I add the line:
active.rnd = integer(random(7));
I had the same problem.
Same with only "random(2);"

btw. thank you for looking into this.

Re: random(var x) - malfunction [Re: TheThinker] #301231
12/09/09 03:42
12/09/09 03:42
Joined: Jul 2008
Posts: 553
Singapore
delinkx Offline
User
delinkx  Offline
User

Joined: Jul 2008
Posts: 553
Singapore
the code runs without crash.

Code:
///////////////////////////////
#include <acknex.h>
#include <default.c>

///////////////////////////////

typedef struct PREPIPE
{
	ENTITY* cell;
	ENTITY* pipes[7];
	var futureZ;
	var rnd;
	struct PREPIPE* next;
	struct PREPIPE* before;
}PREPIPE;

typedef struct PIPE
{
	ENTITY* cell;
	ENTITY* pipes[11];
	var active;
	struct PIPE* slots[4];
	int connected;
}PIPE;

void initLevel();
void createPrePipe();
void preMove(PREPIPE* pre);
void eventClick();
void resetPrePipe();

ENTITY* border;
ENTITY* borderPrev;
ENTITY* arrowsPrev;

PREPIPE preview[5];
PIPE board[10][7];
PREPIPE* active;
PREPIPE* last;

void main()
{
	video_switch(8, 32, 8);
	wait(1);
	level_load("");
	wait(1);
	initLevel();
	wait(-1);
	createPrePipe();
}

void initLevel()
{
	int x; int y; int i;
	VECTOR ta;
	
	mouse_mode = 4;
	mouse_pointer = 2;
	mouse_sync = 1;
	mouse_range = 8000;
	sun_angle.pan = 275;
	sun_angle.tilt = 60;
	
	camera.pan = 90;
	camera.y = -2048;
	camera.x = 576;
	camera.z = 384;
	set(camera, ISOMETRIC);
	camera.arc = 80;
	
	border = ent_create("border.mdl", nullvector, NULL);
	borderPrev = ent_create("borderPrev.mdl", nullvector, NULL);
	arrowsPrev = ent_create("arrowsPrev.mdl", nullvector, NULL);
	
	for(x=0; x<10; x++)
	{
		for(y=0; y<7; y++)
		{
			zero(board[x][y]);
			vec_set(ta, vector(x * 128, 0, y * 128));
			board[x][y].cell = ent_create("cell.mdl", ta, NULL);
			board[x][y].cell.emask |= ENABLE_CLICK;
			board[x][y].cell.event = eventClick;
			board[x][y].cell.skill1 = x;
			board[x][y].cell.skill2 = y;
			board[x][y].cell.skill3 = 0;
			board[x][y].pipes[0] = ent_create("pStartRight.mdl", ta, NULL);
			board[x][y].pipes[1] = ent_create("pStartTop.mdl", ta, NULL);
			board[x][y].pipes[2] = ent_create("pStartLeft.mdl", ta, NULL);
			board[x][y].pipes[3] = ent_create("pStartBottom.mdl", ta, NULL);
			board[x][y].pipes[4] = ent_create("pHor.mdl", ta, NULL);
			board[x][y].pipes[5] = ent_create("pVert.mdl", ta, NULL);
			board[x][y].pipes[6] = ent_create("pCornerTopLeft.mdl", ta, NULL);
			board[x][y].pipes[7] = ent_create("pCornerLeftBottom.mdl", ta, NULL);
			board[x][y].pipes[8] = ent_create("pCornerBottomRight.mdl", ta, NULL);
			board[x][y].pipes[9] = ent_create("pCornerRightTop.mdl", ta, NULL);
			board[x][y].pipes[10] = ent_create("pCross.mdl", ta, NULL);
			for(i=0; i<11; i++)
			{
				set(board[x][y].pipes[i], INVISIBLE);
			}
		}
	}
	
	x = integer(random(10));
	y = integer(random(7));
	i = integer(random(4));
	reset(board[x][y].pipes[i], INVISIBLE);
	board[x][y].cell.skill3 = 1;
}

void preMove(PREPIPE* pre)
{
	int i;
	var acc = 4;
	var fall = 0;
	
	reset(pre.cell, INVISIBLE);
	reset(pre.pipes[pre.rnd], INVISIBLE);
	if(pre.next == NULL){pre.futureZ = 256;}else{pre.futureZ = pre.next.futureZ + 128;}
	
	while(pre.cell.z > pre.futureZ)
	{
		accelerate(fall, acc, 0);
		pre.cell.z -= fall * time_step;
		for(i=0; i<7; i++)
		{
			pre.pipes[i].z -= fall * time_step;
		}
		wait(1);
	}
	pre.cell.z = pre.futureZ;
}

void createPrePipe()
{
	int i; int l;
	var rnd = 0;
	
	for(i=0; i<5; i++)
	{
		zero(preview[i]);
		preview[i].cell = ent_create("cell.mdl", vector(-160, 0, 928), NULL);
		preview[i].pipes[0] = ent_create("pHor.mdl", vector(-160, -32, 928), NULL);
		preview[i].pipes[1] = ent_create("pVert.mdl", vector(-160, -32, 928), NULL);
		preview[i].pipes[2] = ent_create("pCornerTopLeft.mdl", vector(-160, -32, 928), NULL);
		preview[i].pipes[3] = ent_create("pCornerLeftBottom.mdl", vector(-160, -32, 928), NULL);
		preview[i].pipes[4] = ent_create("pCornerBottomRight.mdl", vector(-160, -32, 928), NULL);
		preview[i].pipes[5] = ent_create("pCornerRightTop.mdl", vector(-160, -32, 928), NULL);
		preview[i].pipes[6] = ent_create("pCross.mdl", vector(-160, -32, 928), NULL);
		for(l=0; l<7; l++)
		{
			set(preview[i].pipes[l], INVISIBLE);
		}
		set(preview[i].cell, INVISIBLE);
		rnd = integer(random(7));
		preview[i].rnd = rnd;
	}
	
	preview[0].next = NULL;
	for(i=1; i<6; i++){preview[i].next = &preview[i -1];}
	
	for(i=0; i<5; i++){preview[i].before = &preview[i + 1];}
	preview[5].before = NULL;
	
	for(i=0; i<5; i++)
	{
		wait(-0.5);
		preMove(&preview[i]);
	}
	
	active = &preview[0];
	last = &preview[5];
}

void eventClick()
{
	if(my.skill3 == 0)
	{
		int x = my.skill1;
		int y = my.skill2;
		
		reset(board[x][y].pipes[active.rnd + 4], INVISIBLE);
		my.skill3 = 1;
		resetPrePipe();
	}
}

void resetPrePipe()
{
	int i;
	PREPIPE* tmp;
	
	wait(1);
	//set(active.pipes[active.rnd], INVISIBLE);
	//set(active.cell, INVISIBLE);
	//active.rnd = integer(random(7));
//	vec_set(active.cell.x, vector(-160, 0, 928));
//	for(i=0; i<7; i++)
//	{
//		vec_set(active.pipes[i].x, vector(-160, -32, 928));
//	}
	
//	tmp = active.before;
//	active.next = last;
//	tmp.next = NULL;
//	last.before = active;
//	last = active;
//	active = tmp;
//	
//	wait(-0.5);
//	preMove(tmp);
//	for(i=0; i<4; i++)
//	{
//		if(tmp.before != NULL)
//		{
//			wait(-0.5);
//			tmp = tmp.before;
//			preMove(tmp);
//		}
//		else
//		{
//			break;
//		}	
//	}
}




A7 commercial Team / VC++ 2008 Pro
homepage | twitter | facebook

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