Niantic Studio: How do you make multiple different types of collectibles?

In the Niantic Studio Game Mechanics Basics Workshop, we learn how to make coins for the player to collect. How do I make another type of collectible? Like if I wanted to have bronze, silver and gold coins, how would I program this? I thought if I just made a new object, copied the coin code and changed “coin” to something else, that would make a new collectible, but I keep getting errors no matter where I paste the code.

Here is the code I’ve been trying to change inside the character controller code. I tried pasting the code for the new collectible underneath this, but that gives me errors. How can I add new code to the existing code without getting errors? Also what programing language is this? Or is it unique to Niantic Studio?

// Handle start of a collision
const handleCollisionStart = (e) => {
// Check if the entity involved in the collision is a Coin
if (Coin.has(world, e.data.other)) {
// Remove this coin from the world
world.deleteEntity(e.data.other)
// Trigger the global ‘coinCollect’ event
world.events.dispatch(world.events.globalId, ‘coinCollect’)
// As this is an event-only collision, stop execution of physics collisions
return
}
// If it was not a coin that we collided with, continue with physics collision logic
const data = dataAttribute.cursor(eid)
data.collisionCount++
updateGroundedState()
}

Hi!

This is a great idea!

Would you mind sharing the errors you’re getting? Niantic Studio uses both TypeScript and JavaScript. TypeScript, being a more structured version of JavaScript, can sometimes make it tricky for new users. If you’re finding it challenging, you’re free to change the extension of your components from .ts to .js to avoid running into TypeScript-specific issues.

I changed the file to JavaScript and I put the code in a place that seemed logical, and it works now! I have two collectibles working in my game! I don’t remember the exact errors from when it was TypeScript, but I think it’s just that I was copying and pasting the code in the wrong places and breaking everything that came after.

I’ll keep working in JavaScript from now on. It seems so much easier to experiment in. Thanks for your help!

Here’s how the code looks now that it works:

1 Like