Is there a way to get the length of an array?
Imagine I don't know how many items are in an array, or anything else about its content... is there a way to find the length of the array?
@Deeeds get array length is under logic rather than custom, confused me at first too.
@Jack8680 Brilliant. First part solved.
I'm wanting to spawn a bunch of objects and then place them according to the positional information held in two arrays:
How do I do something like this in this syntactical FARKING nightmare?
Can I have a reference to each one afterwards? Or them have a unique ID that I can somehow know when something hits them?
@Jack8680 The first problem: How do I spawn an object and then have a reference to it so I can change its position?
It seems spawned objects head into the nether.
@Deeeds to spawn them at a position, use 'spawn on area' with the area being the the x and y position for the lower and upper bounds.
To give them an ID, I'd have a main non-spawned object with an idCounter attribute set to 0, then every time an object spawns it gets this value, sets this to its ID, then increments the idCounter variable by 1. They will run in the order they spawn, so you could refer to for example the 8th spawned object by broadcasting a message involving the ID 7, which is the same as the index of the array. and then having the spawned object receive a message based on its ID and run whatever you want it to do.
@Jack8680 I need the objects to know who they are. To say "hey, I'm soo and soo... and this just happened to me..."
@Deeeds do you want a main object to send a message to a spawned object or you want the spawned objects to send a message to a main object? If it's the latter, it's pretty hard because receive message is limited to once per tick.
@Jack8680 When something collides with the spawned objects, I want them to let a central (bonus calculator) know about it, and I want the spawned object to say "It was me!" with an ID that's unique and can be referenced.
@Deeeds have a main object with an attribute like 'idCount', and when objects spawn they use the current state of the main idCount attribute as their own ID and increments the idCount. This way each object's ID is the order in which it spawned.
Also in the spawned object put a collided behaviour to detect the collision. Then broadcast with a key of "bonus" and use the ID of the object as the value.
In your bonus calculator receive with key "bonus" and the value is the ID it can now use.
@Jack8680 I followed this through, as much as I could, and was thinking this way too....
but how do I use that ID in the object as a value? It's referencing the original prototype's ID, not "self's" ID.
idCount = 0
First object spawns
First object sets its ID to idCount (ID=0)
First object increments idCount to 1
Second object spawns
Second object sets its ID to idCount (ID=1)
Second object increments idCount to 2