An annoying issue with my code!

namespace SpriteKind {
export const wall = SpriteKind.create()
}
sprites.onOverlap(SpriteKind.Projectile, SpriteKind.Projectile, function (sprite, otherSprite) {
myDart.startEffect(effects.disintegrate)
myDart.stopDart()
})
controller.A.onEvent(ControllerButtonEvent.Released, function () {
myDart = darts.create(img . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . f . . . . . . . . . . . . . . 1 f . . . . . . . . . . . . . f f f f f f f f f f f f f . . f f 5 f f f f f f f f f 1 f . f f 5 f f f f f f f f f f 2 f f f 5 f f f f f f f f f 1 f . f f f f f f f f f f f f f . . 1 f . . . . . . . . . . . . . f . . . . . . . . . . . . . . , SpriteKind.Projectile)
myDart.throwDart()
myDart.angle = 40
myDart.setTrace(true)
mySprite.setPosition(0, 0)
myDart.setVelocity(75, 75)
})
sprites.onOverlap(SpriteKind.Projectile, SpriteKind.Enemy, function (sprite, otherSprite) {
myDart.startEffect(effects.disintegrate)
myDart.stopDart()
})
sprites.onOverlap(SpriteKind.Player, SpriteKind.Enemy, function (sprite, otherSprite) {
let MixArray: number =
otherSprite.setVelocity(0, 0)
console.log(MixArray.length)
if (otherSprite.image == myEnemy.image) {
MixArray.push(net2)
tiles.placeOnTile(otherSprite, tiles.getTileLocation(6, 0))
console.log(“net”)
} else if (otherSprite.image == myEnemy.image) {
MixArray.push(net3)
tiles.placeOnTile(otherSprite, tiles.getTileLocation(6, 0))
console.log(“net”)
} else if (otherSprite.image == myEnemy.image) {
MixArray.push(net4)
tiles.placeOnTile(otherSprite, tiles.getTileLocation(6, 0))
console.log(“net”)
}
if (MixArray.length == 2) {
console.log(“2”)
effects.confetti.startScreenEffect(500)
for (let value of sprites.allOfKind(SpriteKind.Enemy)) {
value.setVelocity(0, 0)
tiles.placeOnTile(value, tiles.getTileLocation(6, 0))
}
net2 = AI.Mix(
MixArray[0],
2,
2,
MixArray[1]
)
net3 = AI.Mix(
AI.Mix(
MixArray[0],
2,
2,
MixArray[1]
),
2,
2,
AI.Mix(
AI.Mix(
MixArray[0],
2,
2,
MixArray[1]
),
2,
2,
AI.RandomNet(2, 2)
)
)
net4 = AI.Mix(
AI.Mix(
MixArray[0],
2,
2,
MixArray[1]
),
2,
2,
AI.RandomNet(2, 2)
)
info.startCountdown(1)
}
})
let net4: number =
let net3: number =
let myDart: Dart = null
let net2: number =
let myEnemy: Sprite = null
let mySprite: Sprite = null
mySprite = sprites.create(assets.imagePlayerModel, SpriteKind.Player)
effects.blizzard.startScreenEffect(1000)
controller.moveSprite(mySprite, 125, 125)
scene.cameraFollowSprite(mySprite)
tiles.setCurrentTilemap(tilemapThe Map)
tiles.placeOnTile(mySprite, tiles.getTileLocation(1, 35))
mySprite.setStayInScreen(true)
mySprite.setScale(2, ScaleAnchor.Middle)
mySprite.setFlag(SpriteFlag.BounceOnWall, true)
myEnemy = sprites.create(assets.imageEnemy, SpriteKind.Enemy)
myEnemy.setScale(3.5, ScaleAnchor.Middle)
myEnemy.setVelocity((AI.Think(net2, [Math.map(mySprite.x, 23, 137, 0, 1), Math.map(mySprite.y, 24, 104, 0, 1)], 2)[0] - 0.5) * 100, (AI.Think(net2, [Math.map(mySprite.x, 23, 137, 0, 1), Math.map(mySprite.y, 24, 104, 0, 1)], 2)[1] - 0.5) * 100)
myEnemy.follow(mySprite)
This… is my code. I am a relatively novice coder and don’t know much about Javascript, so in your solution please be very detailed and concise so I can fully understand. My issue is this: Problems

1

Dereferencing null/undefined value.

at (line 116)

Here is the problem line:
myEnemy.setVelocity((AI.Think(net2, [Math.map(mySprite.x, 23, 137, 0, 1), Math.map(mySprite.y, 24, 104, 0, 1)], 2)[0] - 0.5) * 100, (AI.Think(net2, [Math.map(mySprite.x, 23, 137, 0, 1), Math.map(mySprite.y, 24, 104, 0, 1)], 2)[1] - 0.5) * 100)

I hope that >main< doesn’t mean there are other issues with the code. Also, this line of code was copied and pasted from the Neural Networks Demo. Please help because I really want this game to succeed!

2 Likes

Next time please just share the project instead of pasting the code. Everything involving these characters: ` gets messed up when you paste because those characters mean something else on this platform!

I’ll take a look at your code and see what I can find

…

Your problem is that net2, net3, and net4 are all empty arrays when you try to “Think”. You need to do something like “net2 = AI.RandomNet(2, 2)” for all of them before you can use them.

1 Like

I’m sorry, this is my first post. Here is the link to the actual project, but please tell me how to fix it with code blocks if possible. I’m horrible with JavaScript. Thanks for your help!

1 Like