#Game stages

16 messages · Page 1 of 1 (latest)

mental star
#
const requiredStage = 'Test'

PlayerEvents.inventoryChanged(event => {
  event.player.tell(event.player.stage);
  if (event.player.inventory.count('kubejs:a_create_blueprint') == 1) {
    event.player.tell('You have gained the knowledge to craft Balls!');
    event.player.add(requiredStage);
  }
})
ServerEvents.recipes(event => {
  const delete_items = [
      'quark:backpack'
  ]
  for (var i = 0; i in delete_items; i++){event.remove({output: delete_items[i]})}
  event.shaped('quark:backpack', [
      'LIL',
      'LCL',
      'LIL'
    ], {
      L: 'minecraft:leather',
      I: 'minecraft:iron_ingot',
      C: '#forge:chests/wooden'
    }).stage(requiredStage)
})

Why doesn't this work?

fresh sorrelBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

rich widget
#
for (var i = 0; i in delete_items; i++)
#

What the heck is this?

mental star
#

The code that has been migrating with me since 1.18.2 xd

rich widget
#

This is a classic-style for loop, so:

  • in initialization part, there's var i = 0 - that's fine
  • in condition part, there's i in delete_items.
    This means, that the loop will execute as long as i is a key of delete_items.
  • in afterthought part, you have i++ - that's fine
#

The condition is suspicious

tranquil rivet
#

craft Balls? pepethink

mental star
#

yes

mental star
rich widget
#

Because I have never seen a classic for loop written like that before, and thought this might be a misunderstanding, but... no, it isn't!

#

As numbers ARE keys of an array

#

So as weird as this looks, the loop is fine

mental star
#

I'm glad my code surprise you

#

what about game stages?

rich widget
#

Though it's recommended instead of doing this:

for (var i = 0; i in delete_items; i++) {
    event.remove({ output: delete_items[i] });
}

do this:

delete_items.forEach(item => {
  event.remove({output: item})
})