Trymunx / Dragon-Slayer-v1

Electron app for the slaying sim
MIT License
0 stars 1 forks source link

Error moving to next map and back straight away #2

Closed Alpvax closed 7 years ago

Alpvax commented 7 years ago

Moving a single tile away and back the error did not reoccur. Might look into it some other time, busy right now.

Crash (with full path stripped to fit them on 1 line):


Uncaught TypeError: Cannot read property 'terrain' of undefined
    at genMap (Dragon-Slayer\js\src\GenerateMap.js:127)
    at Object.GS_GenerateMap.runState (Dragon-Slayer\js\src\GameStates\GS_GenerateMap.js:14)
    at EventEmitter.<anonymous> (Dragon-Slayer\js\src\GameStateManager.js:44)
    at emitOne (events.js:96)
    at EventEmitter.emit (events.js:191)
    at commandParse (Dragon-Slayer\js\src\GameStates\GS_OffPath.js:250)
    at HTMLInputElement.getInputAndParse (Dragon-Slayer\js\src\GameStates\GS_OffPath.js:83)
genMap @ Dragon-Slayer\js\src\GenerateMap.js:127
GS_GenerateMap.runState @ Dragon-Slayer\js\src\GameStates\GS_GenerateMap.js:14
(anonymous) @ Dragon-Slayer\js\src\GameStateManager.js:44
emitOne @ events.js:96
emit @ events.js:191
commandParse @ Dragon-Slayer\js\src\GameStates\GS_OffPath.js:250
getInputAndParse @ Dragon-Slayer\js\src\GameStates\GS_OffPath.js:83```
Trymunx commented 7 years ago

Thanks, it's an error with moving off the west side of the map, not to do with the speed at which you move. I am fairly sure it's something in this section of GenerateMap.js: case "east": position = (Math.round(RNG(sideLength)) * sideLength) - 1;

case "west": position = Math.round(RNG(sideLength - 1)) * sideLength;

I think it's to do with the random number generator and the maths used there to find a position occasionally selecting one that is not part of the map, either -1 or 1 higher than the map's length.

Trymunx commented 7 years ago

Yeah it's position = (Math.round(RNG(sideLength)) * sideLength) - 1; Can give a value of -1, I'll fix it soon.

Trymunx commented 7 years ago

Fix is changing that line to: position = (Math.round(RNG(1, sideLength)) * sideLength) - 1;

Trymunx commented 7 years ago

Fixed.

Alpvax commented 7 years ago

Usual practice is to include this issue number in the commit when you close it

Trymunx commented 7 years ago

Is that #2 or is it listed elsewhere?

Alpvax commented 7 years ago

Exactly

Alpvax commented 7 years ago

I did that as an example of how it should be. If it wasn't already closed it would have closed it too

Alpvax commented 7 years ago

https://help.github.com/articles/closing-issues-using-keywords/ For more info

Trymunx commented 7 years ago

Cool, thanks for the link & example.