#Variables
1 messages · Page 1 of 1 (latest)
wdym
What are you working with so far?
hold on
👍
this
So, I want to make the durability tick down on the tile until it hits 0
then the tile is destroyed
Where's the scriptable object?
GetTile takes in a <T>
right now I have the tile inside of the list in the editor
GetTile<newTile>(pos)
ok also durability needs to be public
var myTile = tilemap.GetTile<newTile>(pos);
Debug.Log(myTile.durability);
use index for array of tiles
Im using tile base
tilebase is the base class
all tiles inherit from it so you can drag any tile there including newTile
var myTile = tilemap.GetTile<newTile>(pos);
Debug.Log(myTile.tiles[0]); // first Tile in list```
I see
okay
I got it to work
but I want the durability to pertain to the type of the tyle
so if I click on a dirt tile, then it gets one shot since it has one durability
and if I click on a stone tile then I need to click it again since it has 2
hold on
also store them as newTile[] not TileBase
since you cant do something specific with TileBase
i mean yeah if you need specifc thing based on type
I need the durability for each tile type to be different so yeah
k lemme implement
durability is already set through its variable
are you trying to add damage or something on this
huh is the tile durable or the weapon
how the two related
durability -= weapon.strength;
if(durability <= 0) {
t.SetTile(cellPosition, null);
}
I got it working
I dont think im doing it very efficiently
wdym
you prob just need some null checks so it doesn't error if you don't have a tile anymore since it's null
this is gonna change durability for all the tiles
lol
I was about to type that
I figured it all out
except that now
hold on I think I have a fix
nvm
doesnt work
hmmm
dont know how to fix this
nvm
I got it
different ways to do it
i was gonna do it like its done in terraria
where if you switch blocks then the progress resets
bc I don't know how to make it individual to each tile
is there a way? Assuming it is easy to implement
maybe using TileData or
store them in a dictionary of tiles with diff data for each one
a dictionary!
I didn't think of that
I need to use both anyway I just realized
hold on
but is it inefficient to add a different tiledata for each tile?
wouldn't that cause lag on a mass scale
🤷♂️ if you're constantly iterating through ALL the tiles maybe , I never had issue yet with that
okay
there are other ways , each has it's own pros and cons, you're gonna have to experiment and adapt
List<TileData> tileDatas;
dataFromTiles = new Dictionary<TileBase, TileData>
foreach(var tdata in tileDatas) {
foreach(var tile in tdata.tiles) {
dataFromTiles.Add(tile, tdata);
}
}
would some loop like this work??
nah you should store their tileboard pos and their data
you could even add the tiles only when you interact with them as well
be mindful what kinda data you truly wanna store anyway
most of it should be only readonly anyway
like durability
you mean health ?
ok
I think this works
then I just subtract directly from the dictionary
rather than the tile itself
thoughts?
I have the key and value swapped
yeah
I just realized that walking back
but this should work
I just have to check to make sure I'm not adding a duplicate
void TileFunct(Vector3Int cellPos)
{
// init new data if tile not present in dict
if (!tilesBoard.ContainsKey(cellPos))
{
tilesBoard[cellPos] = new CustomTileData { Durability = tileType.grass.Durability };
}
CustomTileData tileData = tilesBoard[cellPos];
tileData.Durability--;
// Set the modified value back in the dictionary
tilesBoard[cellPos] = tileData;
if (tilesBoard[cellPos].Durability <= 0)
{
tilemap.SetTile(cellPos, null);
tilesBoard.Remove(cellPos);
}
}```
sum like this should work
just an example , has to be change to account for other things
if (!tilesBoard.ContainsKey(cellPos))
{
tilesBoard[cellPos] = new CustomTileData { Durability = tileType.grass.Durability };
}
thats way better than what i was trying
thanks so much
It feels good to be somewhat done with this
how many hours was this
2 lol
do you do this for like a job or just for a hobby
for fun I guess :p
wow
// init new data if tile not present in dict
if (!tilesBoard.ContainsKey(cellPos))
{
var tile = tilemap.GetTile<BoardTile>(cellPos);
var durability = tile.dataTile.Durability;
tilesBoard[cellPos] = new CustomTileData(durability);
}```
[Serializable]
public struct CustomTileData
{
public int Durability;
public CustomTileData(int durability)
{
this.Durability = durability;
}
}```
public class BoardTile: Tile
{
public CustomTileData dataTile;
}
I didn't need this but thanks!
oh ok cool!
okay I tried to do it without looking at your code
and I got it with no errors
but its not deleting the tiles in the game
!code
📃 Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.
did you look at what I sent
this
?
I tried to do it on my own to understand
I think i see it now
they're about the same but few minor differences
whatexactly are u debugging?
Debug.Log(dataFromTiles);
and then I tried the keys
I wanted the specific data but its just telling me what it is generically
Debug.Log(dataFromTiles.Count);
that seems to be working
I also need to add a catch for when I click on an empty tile
do you wanna just copy / learn from my script i just made that works?
I'd rather stick this out
I just don't understand why mine doesn't
still trying to figure it out
do you know the issue?
hard to tell from here
makes sense
needs more debugs
alright
thank you
ASDFEGBGF
its always the smallest things
//wrong
var newVal = dataFromTiles[cellPosition]--;
//right
var newVal = dataFromTiles[cellPosition] - 1;
Its all solved now
huh.
that was the only issue
it worked for me
it works now so idk
one is subtracting the other is getting last element
the --?
yes that's -= 1
oh I see
in my script i assign it a var first
then change var then put it back in dictionary
is a good way to store bunch of data
I'll try implementing it
you're using structs all the time like whenyou use Vector3
man today just relight my like for coding