Okay, what am I doing wrong here?

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

Previous topic - Next topic

Squinky

Okay, heres all the code:

monster code
if (UsedMode("Use")){
 
 
//-----character attack-----------
chance=Random(20); //define this variable first of course
damage=getstats(0,2);
//damage=getstats(0,2)+Random (3);
if(chance>(getstats(0,3)-getstats(2,1)))
{
 Display ("%d",chance);
setstats (1,1,getstats(1,1)-(damage));
Display ("%d DMG",damage);
Display ("You swing and hit");
}
else
{
Display ("%d",chance);
Display ("You swing and miss");
}
//---------------------------------------------
Room code

int chance= Random (20);

//---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);
//-------------------------

 
Global

int stats[8];

int chance;
int damage;

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

Gilbert
If your talking about those formulas you've posted then no. I don't understand still how to use them, or why I would use them...Where would they apply in my script? And why would some values be correct and others not?

Thanks again for the help, I'm getting confused....

Gilbert

That's the problem:
Code: ags

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

Squinky

#22
Heh, How is that the problem? Are the equations wrong....
* Squinky passes out from confusion

Edit---------------

Holy Crap, I just reread the thread and you guys have been telling me to fix this the whole time! Bah, I'm sorry I didn't get it till now....
so a 2*4 array is x*4+y
and a 2*6 ia x*6+y?

And why did I have to switch from y*4+x??

I hope so, or else I'll have to freak out on all this confusing stuff :P

Gilbert

#23
Right, let's illustrate it as an example:

Say, we want an array of 3*6 elements, so we define it by:
int blah[18]; // 3*6=18
Then, to refer to element [ x ][ y ], we use the formula:
(x * 6 + y) to find it from our array.
Actually the indices are arranged like:


Where the red numbers are the real indices of in the 1D array you created which correspond to each of the elements.

For example, to find element [ 2 ][ 3 ] you can calculate:
2*6+3=15

ie it's blah[ 15 ]

After

#24
Quote from: Squinky on Mon 17/11/2003 05:49:52
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?
You have reversed your x and y, somewhere.
If "0,3" means x=0, y=3, then then conversion is 4*x+y.
What you are getting is stats[4*y+x], which is out of bounds for y>1.

It's only coincidence that the others look right, because (0,1) and (1,0) both happen to be 10.

[edit: oops. too slow again. Oh well, I'll add some more then]
Whether we use
numrows*column+row
or
numcols*row+column
(note the pattern)
is a design choice, and either will work. But it affects how entries are ordered within the array so we must be consistent once we have decided.

Squinky

Gilbert
Sweet! That helps me make sense of things a little better....So using that chart could I just use something like:
if (blah[15]<2){
Display ("Holy crap");
}
or do I still need to do it like I have been:
if (getblah(2,3)<2){
Display ("This is the old way man");
}
I can't tell you how helpful you guys have been
After
You may be late but you've given me some insight I didn't have before. So thank you.

Gilbert

If you just use a fix index, you can just use the blah[15] method, but the getstat() functions would make your codes more readible actually, moreover if you use a variable indices, it would be better to use the get/set stats too, eg:

setstat(row,column); when row and column are 2 variables that may have their values changed in your game.

SMF spam blocked by CleanTalk