Okay, what am I doing wrong here?

Started by Squinky, Mon 17/11/2003 03:09:33

Previous topic - Next topic

Squinky

It tells me that the end of input is reached in the middle of the expression....I'm sure it's simple, but I just can't wrap my brain around it...


//character attack------------------------------
if (Random (20)<(getstats(1,4)-(getstats(2,1){
  setstats (2,2,getstats(1,3)-Random (3));
  Display ("You swing and hit");
 
else if  (Random (20)>(getstats(1,4)-(getstats(2,1){
  setstats (2,2,getstats(1,3)-Random (3));
  Display ("You swing and miss");
}  

Fuzzpilz

Looks like you're missing a few )s and a }  there.

Code: ags

//character attack------------------------------

if(Random (20)<(getstats(1,4)-(getstats(2,1)))
{
setstats (2,2,getstats(1,3)-Random (3));
Display ("You swing and hit");
}
else if (Random (20)>(getstats(1,4)-(getstats(2,1)))
{
setstats (2,2,getstats(1,3)-Random (3));
Display ("You swing and miss");
}


This should work.

Squinky

Thanks,
But it still says the same message on the first line....Man, I'm frustrated
what is missing here?

Gilbert

Didn't see the problem to fuzz's code, maybe there're more missing stuffs in other perts of the code, you may need to post the whole function here.

Hmmmm I don't know, unless it is your intention, as you called Random(20) twice, so, if the player didn't "hit", due to that extra random(20) in the else part, it would randomize again, and probably won't give you the "missed" response most of the time.I suggest it to be:
Code: ags

//character attack------------------------------
chance=Random(20); //define this variable first of course
if(chance<(getstats(1,4)-(getstats(2,1)))
{
setstats (2,2,getstats(1,3)-Random (3));
Display ("You swing and hit");
}
else if (chance>(getstats(1,4)-(getstats(2,1)))
{
setstats (2,2,getstats(1,3)-Random (3));
Display ("You swing and miss");
}


And currently the code would od nothing if chance equals (getstats(1,4)-(getstats(2,1)), if that's not what you want, the simplest code would be just:
Code: ags

//character attack------------------------------
chance=Random(20); //define this variable first of course
if(chance<(getstats(1,4)-(getstats(2,1)))
{
setstats (2,2,getstats(1,3)-Random (3));
Display ("You swing and hit");
}
else
{
setstats (2,2,getstats(1,3)-Random (3));
Display ("You swing and miss");
}


Fuzzpilz

I'm not sure... what's the exact error message? Could you post that getstats function?

(Also: this code might be wrong for what you're trying to do - I don't exactly know what this is, of course, but it looks as if you should remove the second if.)

Squinky

Gilbot, good catch. With my old script, the second part was even needed so much. But even with these new scripts you guys have provided, it still gives the same error.

The error
end of input reached in the middle of expression
refering to the first line.

What it's for
I'm using a 2*4 array to hold stats for the char and a bad guy. With these stats, I'm hoping to use fashion a battle system based off of Dungeons and dragons mechanics.
so if your familair with that system stats(1,4) is the chars attack rating or thaco, and stats(2,1) is the monsters armor rating.

all the code

//in the monster guys character code:

chance=Random(20); //define this variable first of course
if(chance<(getstats(1,4)-(getstats(2,1)))//this line is the problem one<--
{
setstats (2,2,getstats(1,3)-Random (3));
Display ("You swing and hit");
}
else
{

Display ("You swing and miss");
}

//in the room script, first time enters screen:

int chance=Random (20);

//---char attributes----
setstats (1,1,8);
setstats (1,2,10);
setstats (1,3,-3);
setstats (1,4,18);
//-----mon attribute--------
setstats (2,1,10);
setstats (2,2,10);
setstats (2,3,-2);
setstats (2,4,20);
//-------------------------

//In the global script

int stats[8];

int chance;



function getstats(int x, int y) {
return stats[y * 5 + x];
}
function setstats(int x, int y, int value) {
stats[y * 5 + x] = value;
}

//In the script header

/**/import function getstats(int,int);
/**/import function setstats(int,int,int);

And that should be everything tied to this event....


After

#6
[edit: for latest version]
Remove red:--

if(chance<(getstats(1,4)-(getstats(2,1)))//this line is the problem one<--

I assume spaces are allowed between function names and parentheses? (I never write them like that so I wouldn't know)

Fuzzpilz

Whitespace isn't a problem, no.

Seems Gilbot and I both overlooked the extra ( before the second getstats.

Squinky

Quote from: Fuzzpilz on Mon 17/11/2003 03:58:20
Seems Gilbot and I both overlooked the extra ( before the second getstats.

Yeah, don't feel bad, I did for like an hour....It's compiling and working now, but the math is'nt turning out right, no matter how many times I hit it says the monsters hitpoints are -4 or -3. Any idea what I'm doing there?

Also where would be the proper place to declare that chance=Random (20) bit?

Gilbert

#9
:p

Just declare the chance on top of that script:
int chance;

Hmm I didn't read the codes carefully, but if you're making 2*4 arrays, the correct formula to get the index from [ x ][ y ] is:

x*4+y

Fuzzpilz

#10
Code: ags

setstats(2,2,getstats(1,3)-Random (3));


This seems to be the problem. Using getstats(2,2) - getstats(1,3) + Random(3) should fix it, I think. As for the chance thing, you don't really need it. Just use the Random(20) directly and leave out the second if.

Also, remove the setstats out of the second block.

After

#11
Your arrays are all over the place, man! ;D

Have to fix them first.

int stats[8];
is correct, and will accept indices 0..7 (8 values).

Your coordinates should be x in {0,1}, y in {0,1,2,3}.

And the conversion should be 4*x+y.
(or x+2*y, just choose one though)

I don't know how 'hitpoints' emerge from your code, so I can't say more, but your arrays will be giving you garbage anyway.

Squinky

Thanks for all the great help everybody!

Quote from: Gilbot V7000a on Mon 17/11/2003 04:18:52

Hmm I didn't read the codes carefully, but if you're making 2*4 arrays, the correct formula to get the index from [ x ][ y ] is:

x*4+y

I get the math, but I don't don't what this is for....I remember you telling me this kinda stuff in my arrays thread, but can't I just access it with the neat little function chris put up? using setstats and getstats?

Fuzz
Yeah, I've removed the second block setstats, and changed to getstats(2,2) - getstats(1,3) + Random(3) for dmg calculations, but it is still wonkey:
What It should be doing is 3+random 3 with a max of 6...but the monster starts with 10 hp and it always seems to take him down to at least 0 in the first hit. Then after it gets to 0 it stays around -3 or -4 no matter how much more dmg is inflicted. Sometimes it almost seems like its adding back hp after it hits below zero....

After

#13
Quote from: Squinky on Mon 17/11/2003 04:36:47I get the math, but I don't don't what this is for.
This may help clarify what's going on.
Code: ags

....x..0..1.
.y....------
.0...|.0..4.
.1...|.1..5.
.2...|.2..6.
.3...|.3..7.

Multiplying means adding whole extra columns, we then add the offset from the start of the column to get the exact position.
Imagine starting somewhere in the left column. Adding 4 moves you to the next one.

Fuzzpilz

#14
If it's supposed to be 3 plus random, you should use getstats(2,2) - getstats(1,3) - Random(3).

Concerning the actual problem, I'm not sure. Could you post the getstats and setstats you're using now? If you're doing it differently in each, that might be it.

Squinky

#15
Quote from: After on Mon 17/11/2003 04:35:51
Your arrays are all over the place, man! ;D

Have to fix them first.

int stats[8];
is correct, and will accept indices 0..7 (8 values).

Your coordinates should be x in {0,1}, y in {0,1,2,3}.

And the conversion should be 4*x+y.
(or x+2*y, just choose one though)

I don't know how 'hitpoints' emerge from your code, so I can't say more, but your arrays will be giving you garbage anyway.

Okay, so it should look like this, right? 0 to 3 for stats[8];



Fuzz

I'll try fiddling around with both ways. I think I've reached a point where I can statrt a new test game and only use what works and go from there. I don't know if that makes sense, but the old test game was full of garbage code that I'm afraid might interfere....I'm going to make script this one so I can see the random results and figure out why there doing what there doing...Then if that dosen't work...who knows...

Gilbert


Squinky

Well, at least I got that right now :p

On to the next issue

Okay so I made a new test game where I could check the dmg I was generating, now I simplified it and it should have simply been 3, but no it tells me something like 186778788 or some other riduculous number....

So I made a room with my graph above that I could go to to check values of the array. Heres what I set them to:

//---char attributes----
setstats (0,0,8);
setstats (0,1,10);
setstats (0,2,3);
setstats (0,3,18);
//-----mon attribute--------
setstats (1,0,10);
setstats (1,1,10);
setstats (1,2,2);
setstats (1,3,20);
//-------------------------

Problem is that 0,2 and 1,2 both have crazy big numbers and 0,3 and 1,3 read as 0.....

So am I not setting the array properly somehow and writing values into weird places or am I grabbing weird values from other places?


 

Fuzzpilz

Again, post the getstats and setstats you're using. It certainly looks as though that's where the problem is.

Gilbert

hmmm are you sure you are using the correct formula for the indices in setstat and getstat? Seems that you're grabbing values from outside the array boundary.

SMF spam blocked by CleanTalk