PDA

View Full Version : board[] array and stuff


JoMomma
03-18-2001, 02:44 AM
Horay I finally get to post on here! I think... Anyway...

Ok, from what I understand, board[] contains information about the tiles that are on that level. Now I decided to make a stupid little npc that does:
setplayerprop #c,#v(board[playerx+playery*64]);

With this, I could actually look at what types of values are in the array. I'd expect things like 10, or 20, or maybe 200... but here I get like 2096 (or something close to that) for grass.

Anyway my 3 questions are as follows:
1) Since it's a 64x64 array but there can be really 4 tiles per section of that board, what determines the value? is it an "anded" value of the 4 tiles? And if so, what order is it in?

2) How exactly does changing tiles work? I kinda understand updateboard, but don't fully get it. I'd also like to know if maybe putting this type of code in the NPC server would make it global to all users. I've heard that it's only really local, but the documentation does say it's temporaray.

3) What actually determines the values? Like what makes grass 2096 (or whatever it was)? Is it the position they're in the pics1.png?

Happily making his first post (since the damn thing didn't send me a verification code right away!)

-- JoMomma

Lion'el-Jonson
03-18-2001, 03:02 AM
. . .

Fai
03-18-2001, 04:31 AM
if (playertouchsme) {
shootball;
}

Tyhm
03-18-2001, 05:27 AM
Open hammer.txt or shovel.txt
It explains it rather better than I can.
One number in the value of the array is the first coordinate when you mousover the tiling pallette, the other is (naturally) the other coordinate.
And of course, one value in the array's index calculator is the x, the other is the y.
I always get them confused though, and what numbers one is supposed to multiply by...

freddyfox
03-18-2001, 05:58 AM
I suppose I will eventually have to figure out what that means. *Heads spins*

kyle0654
03-18-2001, 07:40 AM
1) Since it's a 64x64 array but there can be really 4 tiles per section of that board, what determines the value? is it an "anded" value of the 4 tiles? And if so, what order is it in?

2) How exactly does changing tiles work? I kinda understand updateboard, but don't fully get it. I'd also like to know if maybe putting this type of code in the NPC server would make it global to all users. I've heard that it's only really local, but the documentation does say it's temporaray.

3) What actually determines the values? Like what makes grass 2096 (or whatever it was)? Is it the position they're in the pics1.png?

First, you need to understand how it works:

board[x + y * 64] = tilex + tiley * 16;

The y will always get bigger, while the x goes from 0 to 15 then loops back to 0. If you run your mouse over the tileset on the right side, you'll see the values in the bottom right change. It tells you the tilex and tiley of the tile you are hovering over. If you go from left to right in a straight line, you'll notice that the tilex will go to 15 then to 0, and the tiley will jump up a lot. Well, this is because the tileset isn't arranged from left to right, it's arranged in strips that are 16 tiles wide and however many tiles tall.

Okay, too many words eh? Anyways, back to what I was gonna say. If you want to change a board tile, you must know what tile you are replacing with in terms of its tilex and tiley on the tileset. once you know that, you can use the equation above to set it. Then update the board using this:

updateboard x, y, 1, 1;

That will load the current tile at that position. Of course, this is all client-side, and only certain tiles will work well online. Bushes to stumps, Rocks to holes, and signs to holes I think will work.

Anyway, if you want to know the tilex and tiley of what tile you're standing on:

boardvalue = board[playerx + playery * 64];
setplayerprop #c,tilex: #v(boardvalue%16), tiley: #v(int(boardvalue/16));

And of course use that in a timeout script.

Btw, doing %16 or %# just find the remainder of the number when you divide it by 16, if you didn't know that already.


Now, as for global tile changes using an npc server...I know how you would do it, but you better ask Stefan, cuz I don't think the command is really open to public as of yet, and it's server-side too, meaning it won't work offline.


Well, did I thoroughly confuse you? As Tyhm said, a great example to look at is the shovel or hammer script if you want to see it in action.

JoMomma
03-19-2001, 01:35 AM
Originally posted by kyle0654
First, you need to understand how it works:

board[x + y * 64] = tilex + tiley * 16;

The y will always get bigger, while the x goes from 0 to 15 then loops back to 0. If you run your mouse over the tileset on the right side, you'll see the values in the bottom right change. It tells you the tilex and tiley of the tile you are hovering over. If you go from left to right in a straight line, you'll notice that the tilex will go to 15 then to 0, and the tiley will jump up a lot. Well, this is because the tileset isn't arranged from left to right, it's arranged in strips that are 16 tiles wide and however many tiles tall.

Okay, too many words eh? Anyways, back to what I was gonna say. If you want to change a board tile, you must know what tile you are replacing with in terms of its tilex and tiley on the tileset. once you know that, you can use the equation above to set it. Then update the board using this:

updateboard x, y, 1, 1;

That will load the current tile at that position. Of course, this is all client-side, and only certain tiles will work well online. Bushes to stumps, Rocks to holes, and signs to holes I think will work.

Anyway, if you want to know the tilex and tiley of what tile you're standing on:

boardvalue = board[playerx + playery * 64];
setplayerprop #c,tilex: #v(boardvalue%16), tiley: #v(int(boardvalue/16));

And of course use that in a timeout script.

Btw, doing %16 or %# just find the remainder of the number when you divide it by 16, if you didn't know that already.


Now, as for global tile changes using an npc server...I know how you would do it, but you better ask Stefan, cuz I don't think the command is really open to public as of yet, and it's server-side too, meaning it won't work offline.


Well, did I thoroughly confuse you? As Tyhm said, a great example to look at is the shovel or hammer script if you want to see it in action.

It did at first. Then I looked at the hammer code and kinda understood it... then I decided to open graal and I finally got it... I'm glad you said "tilex" cause someone else said "x" when they tried to explain what the value was. But these tiles are all over the place so I'm not sure what I'll do. Basically I was gonna make a weather system that changes the tiles to snow ones if it's snowing... Possible? More than likely, yes. Easy? No, mainly cause the values of the grass tiles aren't next to each other, and I don't think I can modify/chec them with math (ie: add 200 to make it a grass tile, or if it's between 100 and 150 it's a grass tile... that just ain't gonna work).

But I do wonder how tiles that are on the 1/2 mark of a coordinate (ie: x of 25.5) are gonna be read. Does the array somehow accept floating point numbers as an index?

kyle0654
03-19-2001, 04:04 AM
oops, sorry. Like an array, you must first do int(x) on the boardx you are checking to make sure that you are checking the tile on that array position. It stores whole number values for tile positions, not decimals, so you need to truncate it (what int does...cuts off decimals)

A weather system that does that would be pretty cool, and I think I know how you could achieve it pretty simply....although to actually implement it and have it work online would be another story...

Use two arrays, one called weather.grasstiles, and the other called weather.snowtiles. Store corresponding tiles in the same position in the array (you're gonna need ta know arrays pretty well), and just check for both positions every timeout and replace based on the season.

Here, I'll give you a little example. Say that 2000 is normal grass, 3000 is normal snow, 2001 is a grass corner, and 3001 is the same type of corner, but with snow:


if (created) {
weather.grasstiles = {2000, 2001};
weather.snowtiles = {3000, 3001};
weather.season = 0;
// Seasons:
// 0 - Summer
// 1 - Winter
timeout = .1;
}
if (timeout) {
for (this.x = 0; this.x <= 64; this.x++) {
for (this.y = 0; this.y <=64; this.y++) {
this.boardvalue = board[this.x + this.y * 64];
if (this.boardvalue in weather.grasstiles || this.boardvalue in weather.snowtiles) {
getarrayposition();
board[this.x + this.y * 64] == (weather.season == 0)? weather.grasstiles[this.arraypos] : weather.snowtiles[this.arraypos]);
}
}
}
updateboard 0, 0, 64, 64;
timeout = 5;
}

function getarrayposition() {
for (this.arraypos = 0; this.arraypos < arraylen(weather.grasstiles); this.arraypos++) {
if (this.boardvalue == weather.grasstiles[this.arraypos] || this.boardvalue == weather.snowtiles[this.arraypos]) break;
}
}


That uh....should work.....not entirely sure it will. If it doesn't, tell me and I'll go find my old random tile replacing script I did one day when I was bored. Just whatever you do, do a timeout at about 5 or more if you're doing updateboard, I'd even suggest 10 or 20 maybe...

If that break in the function doesn't work, replace it with something like this.ap = this.arraypos and make sure you replace the things up above. This script is longer than necessary, but better for showing how things are done.

JoMomma
03-19-2001, 09:17 AM
Originally posted by kyle0654
oops, sorry. Like an array, you must first do int(x) on the boardx you are checking to make sure that you are checking the tile on that array position. It stores whole number values for tile positions, not decimals, so you need to truncate it (what int does...cuts off decimals)


Ok but... what if we have say...

plain grass, red flower
grass blade left, grass blade right

That's 4 "tiles" which is one unit in the board array. So which one would come up? And how do I get the other ones? Or is the array even bigger than I thought?

Thak2
03-19-2001, 08:20 PM
If it has a
green tile,flower tile,
leftgrass tile, rightgrass tile
then it would be a 2x2 square, so if you were just using that you would have this.x+64*this.y for your top left one, this.x+1+64*this.y for the top right, and this.x+1+64*(this.y+1) for the bottom right, and so on...

But to have the tiles cover the whole screen in a 2x2 square pattern I am not sure how to do it... could there be a way to skip every other number, or use even numbers only/odd numbers only?

vergil
03-19-2001, 11:45 PM
Originally posted by Fai
if (playertouchsme) {
shootball;
}
Absolutely brilliant.. i never would have thought of it..

JoMomma
03-20-2001, 03:03 AM
Oh wait I see what my problem was: I didn't realize that something like x of 2.5 was in the MIDDLE of a tile... doy! I thought a 2 tile by 2 tile "object" took up one unit... duh for me!