0 registered members (),
1,209
guests, and 0
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
random(var x) - malfunction
#301219
12/09/09 01:24
12/09/09 01:24
|
Joined: Jun 2006
Posts: 214 Germany, NRW
TheThinker
OP
Member
|
OP
Member
Joined: Jun 2006
Posts: 214
Germany, NRW
|
Can you explain this behavior of "random(var x)" Here my function:
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: delinkx]
#301228
12/09/09 03:12
12/09/09 03:12
|
Joined: Jul 2008
Posts: 553 Singapore
delinkx
User
|
User
Joined: Jul 2008
Posts: 553
Singapore
|
i tested ur code. and i dont get any crash. here is the sample i used:
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]);
}
|
|
|
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
TheThinker
OP
Member
|
OP
Member
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:
void resetPrePipe()
{
var rnd;
random(2);
}
same problem here. Updated version of the whole script...:
///////////////////////////////
#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
User
|
User
Joined: Jul 2008
Posts: 553
Singapore
|
the code runs without crash.
///////////////////////////////
#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;
// }
// }
}
|
|
|
|