Is adding a tag to an object possible?

I’m making a game with pretty basic rpg like movement.
And im having some trouble with wall collision.

I have it to where their is always a ball in front of the player checking for a wall.
If it sees one then it stops the player from moving in that direction.

The issue is that I don’t know how to get it to desern normal objects from walls.
I could add each individual wall into the code by hand but that feels redundant and way too time consuming.
So I was wondering if their is any way to give the object a kind of classification that can be checked to tell that it’s a wall.

Like a
if (this.hits(var.wall)) [xdirectionavalible=false]
Where the object can hold that variable to be checked.

Sorry if this dosent make sense. I’m not entirely sure how to explain it

are you looking for something called a variable?

var name = {your object here};

The main issue is that I’m trying to make something have collision. But I want to do it by simply adding a small line into it rather then writing the whole collision system on every single object.

A function ig

Here is the wik file.

My Project12-20-2024_6-58-31PM.wick (4.5 KB)

I’m not sure if the send worked.
It has WASD controls.
The blue box is the main player location, the pink box is where the sprite will be, the black orbs are collision detectors to stop the player from running into walls, and the orange box is the wall.
I want to make multiple of the walls without having to redo the code for every individual wall.

Their is a test variable in the frame. Turn that on to see the collision stuff

Btw. The collision detection that’s red is bugged. Idk why. I’m just not gonna touch it for now

if you create a global array, like project.walls = [];, you can then have each wall’s default script say project.walls.push(this); to add itself to the array.

then, you can use your collision code on everything that is in project.walls.

1 Like

I tried this and I keep getting an error that says “cannot read properties of undefined(reading ‘view’)” and im not sire what it means

Edit: I found the issue, it was just looking for the wrong thing. But now I have another issue.
I cant get the hittest to read the array and identify the things in it. It just reads that their is an object in the array, not what it is.

My Project12-21-2024_5-49-50PM.wick (11.5 KB)

I have no idea what I’m doing T^T

I’ve cut out a bunch of the other stuff I’m working on so this looks weird.

try using this code instead. you want to iterate through the array of walls to check the collision.

(the object Object is actually fine, the array does contain the wall but it doesn’t do a great job of representing it in text)

Thanks. I’ll try that out rn.
But is it alright if I get an explanation on how “for” “let” and “of” work?
I’m pretty new to actually making functional things so I don’t really know.

Edit: I’ve looked at it for a little now and I think I get the gist. explanation would still help, but thank you SO MUCH. I really appreciate the help

the for works as any for loop does, so w is being iterated over.

let is just another way to make a variable. there are subtle differences between let and var that even i’m not really aware of, but with wick, i default with let. if i remember, var is for a global variable that never gets destroyed, and let is for a local variable that gets destroyed when you go out of the “scope”. for the most part though, they are very very similar.

the of format of a for loop is just another way to use a for loop. usually you have the 3 parts separated by semicolons, and (generally) you walk through a set of numbers. but with of, you are walking through each item in an array like project.walls.