Author Topic: Script crashes game  (Read 1380 times)

Code: [Select]
$dungeon_chars = "x o";

function dungeon_make(%dir) {
%file = new fileObject();
%file = openForRead("config/client/Dungeons/dungeon1.txt");
while(!%file.isEOF()) {
%line=%file.readline();
if(strLen(%line) > 2) {
%dungeon_length=getwordcount(%line);
for(%i="-1";%i<%dungeon_length;%i++) {
%tempchar=getword(%line,%i);
if(%tempchar !$= getword($dungeon_chars,0) || %tempchar !$= getword($dungeon_chars,1)) {
error("Dungeon Builder: Unrecognized character. Unable to continue.");
return;
}
else {
if(%tempchar $="x") {
placeBrick(1);
schedule(500,0,commandtoserver,supershiftbrick,0,0,1);
placebrick(0);
schedule(500,0,commandtoserver,supershiftbrick,1,0,1);
}
if(%tempchar $="o") {
schedule(500,0,commandtoserver,supershiftbrick,1,0,0);
}
if(%tempchar $="") {
schedule(500,0,commandtoserver,supershiftbrick,-1*%dungeon_length,-1,0);
}
}
}
}
}
}

Whenever I attempt to run this script, it always crashes. When I check the console.log, I find this:
Code: [Select]
add-ons/script_dungeongen/client.cs (7): Unable to find object: '' attempting to call function 'readLine'
BackTrace: ->ConsoleEntry::eval->dungeon_make

add-ons/script_dungeongen/client.cs (0): Unable to find object: '' attempting to call function 'isEOF'
BackTrace: ->ConsoleEntry::eval->dungeon_make
...repeated so many times it crashes.

Does anyone see my error here? I used to have it go to %dir (a directory), but I changed it to see if it would fix the crash.

Also, I know that I forgot to %file.close(); and %file.delete(); but I don't think that would be causing the problem, as it's being bad on the reading of the file.

Look at my fourth reply.
« Last Edit: May 25, 2011, 07:13:41 AM by Placid »

%file = openForRead

What.

oh holy forget what

Just change
Code: [Select]
%file = openForRead("config/client/Dungeons/dungeon1.txt");to
Code: [Select]
%file.openForRead("config/client/Dungeons/dungeon1.txt");

Alright, I fixed that, and yes, I knew, Amade.

I also fixed the fact that placeBrick isn't a function. I added echos to see where it comes out and all that.
It still crashes, however, it's running through the full script and should be placing the bricks, but it's not. Anyone got any suggestions?

It ran through every brick's loop.

serverCmdPlaceBrick isn't it? Something like that?
commandToServer('placeBrick');

Use commandToServer('plantBrick');

Also, can you post your console log along with an updated script showing where your echoes are?

Change this:
Code: [Select]
for(%i="-1";%i<%dungeon_length;%i++)
to this:
Code: [Select]
for(%i=0;%i<%dungeon_length;%i++)

Change the schedules so they're not all at the same time:
Code: [Select]
%time += 500;
schedule(%time,...)

Here's the code:
Code: [Select]
$dungeon_chars = "x o";

function dungeon_make(%dir) {
%file = new fileObject();
%file.openForRead("config/client/Dungeons/dungeon1.txt");
while(!%file.isEOF()) {
%line=%file.readline();
if(strLen(%line) > 2) {
%dungeon_bcount="0";
%dungeon_length=getwordcount(%line);
for(%i="-1";%i<%dungeon_length;%i++) {
%tempchar=getword(%line,%i);
if(%tempchar $="x") {
plantBrick(1);
schedule(500,0,commandtoserver,supershiftbrick,0,0,1);
plantbrick(0);
schedule(500,0,commandtoserver,supershiftbrick,1,0,1);
%dungeon_bcount++;
echo("Placing brick: " @ %dungeon_bcount @ ".");
}
if(%tempchar $="o") {
schedule(500,0,commandtoserver,supershiftbrick,1,0,0);
%dungeon_bcount++;
echo("Omitting brick: " @ %dungeon_bcount @ ".");
}
if(%dungeon_bcount $= %dungeon_length) {
schedule(500,0,commandtoserver,supershiftbrick,-1*%dungeon_length,-1,0);
}
}
}
}
}
note that the whole brackets thing might be a bit messy, but it does execute.

...and here's the console part where it starts to echo:
Code: [Select]
==>dungeon_make();
Placing brick: 1.
Placing brick: 2.
Placing brick: 3.
Placing brick: 4.
Placing brick: 5.
Placing brick: 6.
Placing brick: 7.
Placing brick: 8.
Placing brick: 9.
Placing brick: 10.
Placing brick: 1.
Omitting brick: 2.
Omitting brick: 3.
Placing brick: 4.
Omitting brick: 5.
Omitting brick: 6.
Placing brick: 7.
Omitting brick: 8.
Omitting brick: 9.
Placing brick: 10.
Placing brick: 1.
Omitting brick: 2.
Placing brick: 3.
Omitting brick: 4.
Placing brick: 5.
Omitting brick: 6.
Omitting brick: 7.
Placing brick: 8.
Omitting brick: 9.
Placing brick: 10.
Placing brick: 1.
Omitting brick: 2.
Omitting brick: 3.
Omitting brick: 4.
Omitting brick: 5.
Placing brick: 6.
Omitting brick: 7.
Omitting brick: 8.
Omitting brick: 9.
Placing brick: 10.
Placing brick: 1.
Omitting brick: 2.
Omitting brick: 3.
Placing brick: 4.
Omitting brick: 5.
Placing brick: 6.
Placing brick: 7.
Omitting brick: 8.
Placing brick: 9.
Placing brick: 10.
Placing brick: 1.
Placing brick: 2.
Omitting brick: 3.
Omitting brick: 4.
Omitting brick: 5.
Placing brick: 6.
Placing brick: 7.
Omitting brick: 8.
Placing brick: 9.
Placing brick: 10.
Placing brick: 1.
Omitting brick: 2.
Omitting brick: 3.
Placing brick: 4.
Omitting brick: 5.
Placing brick: 6.
Omitting brick: 7.
Omitting brick: 8.
Omitting brick: 9.
Placing brick: 10.
Placing brick: 1.
Omitting brick: 2.
Omitting brick: 3.
Omitting brick: 4.
Omitting brick: 5.
Omitting brick: 6.
Omitting brick: 7.
Omitting brick: 8.
Omitting brick: 9.
Placing brick: 10.
Placing brick: 1.
Placing brick: 2.
Placing brick: 3.
Omitting brick: 4.
Omitting brick: 5.
Placing brick: 6.
Omitting brick: 7.
Placing brick: 8.
Placing brick: 9.
Placing brick: 10.
Placing brick: 1.
Placing brick: 2.
Placing brick: 3.
Placing brick: 4.
Placing brick: 5.
Placing brick: 6.
Placing brick: 7.
Placing brick: 8.
Placing brick: 9.

It runs through each row and assigns each brick a number. I believe it crashes as it places the last brick, but I'm not quite sure.

1. Change this:
Code: [Select]
for(%i="-1";%i<%dungeon_length;%i++)
to this:
Code: [Select]
for(%i=0;%i<%dungeon_length;%i++)

2. Change the schedules so they're not all at the same time:
Code: [Select]
%time += 500;
schedule(%time,...)
1. I wanted it to start at zero and go up, as it's getting a word from a line. Wouldn't I need to start at "-1" because as you state it the variable gets incremented, or am I understanding the order of things wrong?
2. What would this change? I thought I had the delays in the function, and it's not that I don't believe you, I'd like an explanation about what it would do for the function.
« Last Edit: May 25, 2011, 07:12:01 AM by Placid »

1. The %i= part of the for statement is what the value starts as, the end part is what it does AFTER the stuff inside the for loop has been processed.
2. At the moment you're scheduling for 500 milliseconds, and because it's just looping straight through them it's going to do every single shift of the brick in 500 milliseconds, rather than having a 500 millisecond gap. Either remove the schedules altogether or make it like that.
The reason it's crashing is probably because you're overflowing it with useless schedules that all happen at the same time.
Also, change placeBrick to commandToServer('plantBrick'); like suggested earlier.

2. At the moment you're scheduling for 500 milliseconds, and because it's just looping straight through them it's going to do every single shift of the brick in 500 milliseconds, rather than having a 500 millisecond gap. Either remove the schedules altogether or make it like that.
The reason it's crashing is probably because you're overflowing it with useless schedules that all happen at the same time.
What he said..

you can also try something like this:
schedule(500 * %a ,0,

so your schedules wont happen all at the same time.

And lastly - im not sure if the arguments are correct here:
Code: [Select]
schedule(500,0,commandtoserver,supershiftbrick,0,0,1);

do a trace for supershiftbrick and check the arguments.  I suspect you will need to do something like this instead:
Code: [Select]
schedule(500,0,commandtoserver,supershiftbrick,"0 0 1");


Supershiftbrick has four arguments, as I'm aware. Not sure what the first one is though, it's usually a four of five digit number.

1. The %i= part of the for statement is what the value starts as, the end part is what it does AFTER the stuff inside the for loop has been processed.
2. At the moment you're scheduling for 500 milliseconds, and because it's just looping straight through them it's going to do every single shift of the brick in 500 milliseconds, rather than having a 500 millisecond gap. Either remove the schedules altogether or make it like that.
The reason it's crashing is probably because you're overflowing it with useless schedules that all happen at the same time.
Also, change placeBrick to commandToServer('plantBrick'); like suggested earlier.
Alright, so I should change it to a variable set to 500. Gotcha.
And lastly - im not sure if the arguments are correct here:
Code: [Select]
schedule(500,0,commandtoserver,supershiftbrick,0,0,1);

do a trace for supershiftbrick and check the arguments.  I suspect you will need to do something like this instead:
Code: [Select]
schedule(500,0,commandtoserver,supershiftbrick,"0 0 1");
I looked up a servercommand list, and it's /supershiftbrick X Y Z. I'm not quite sure if that would go "x y z" or x, y, z, but I'll test around with it later.

At the moment I will not be able to work on this due to finals being tomorrow. I'll work on it Friday.

Supershiftbrick has four arguments, as I'm aware. Not sure what the first one is though, it's usually a four of five digit number.
That would be the client. It's a serverCmd, so there has to be one.

That would be the client. It's a serverCmd, so there has to be one.
That's what I thought, but it always changes, so it can't be.
« Last Edit: May 26, 2011, 04:58:35 PM by Treynolds416 »