#String equality not working

109 messages · Page 1 of 1 (latest)

brittle arch
#

i have no idea whats going on, Im going insane

const id : string = decoder.decode(ClientComponent.string[eid]);
      console.log("id:", id);
      const channelId = <string>channel.id;
      console.log("channelId", channelId);
      if(id === channelId)
      {
        // decode input
        InputComponent.x[eid] = inputArray[1];
        InputComponent.y[eid] = inputArray[2];
        console.log("hit");
      }

gameserver:dev: id: QYlQ7aEk6xGQ3jUsRAbDe3EX
gameserver:dev: channelId QYlQ7aEk6xGQ3jUsRAbDe3EX
gameserver:dev: id: QYlQ7aEk6xGQ3jUsRAbDe3EX
gameserver:dev: channelId QYlQ7aEk6xGQ3jUsRAbDe3EX
gameserver:dev: id: QYlQ7aEk6xGQ3jUsRAbDe3EX
gameserver:dev: channelId QYlQ7aEk6xGQ3jUsRAbDe3EX

These are the same strings right????? am i crazy???

idle dew
#

<string>channel.id doesn't actually make it a string, what is typeof channel.id?

subtle oysterBOT
#
export type ChannelId = string | undefined
subtle oysterBOT
#
private _id: Types.ChannelId
brittle arch
#

gameserver:dev: channelId fPduJXYCZnCSOb0UMJD0cLp0
gameserver:dev: id: fPduJXYCZnCSOb0UMJD0cLp0
gameserver:dev: string
gameserver:dev: channelId fPduJXYCZnCSOb0UMJD0cLp0
gameserver:dev: id: fPduJXYCZnCSOb0UMJD0cLp0
gameserver:dev: string
gameserver:dev: channelId fPduJXYCZnCSOb0UMJD0cLp0

idle dew
#

Huh

#

typeof id?
Possibly this:

new String("x") === "x"
// => false
brittle arch
#

i guess ill just do that yeah

#

okay so for this code

#
const inputArray = <number[]>data;
    
    const ents = inputQuery(world);
    for (let i = 0; i < ents.length; i++) {
      const eid = ents[i];
      // decode id
      const id : string = decoder.decode(ClientComponent.string[eid]);
      console.log("id:", id);
      console.log("channelId", channel.id);
      if(id === new String(channel.id))
      {
        // decode input
        InputComponent.x[eid] = inputArray[1];
        InputComponent.y[eid] = inputArray[2];
        console.log("hit");
      }
    }
#

gameserver:dev: id: qRja5juBIRVEgFie7FqPiLVm
gameserver:dev: channelId qRja5juBIRVEgFie7FqPiLVm
gameserver:dev: id: qRja5juBIRVEgFie7FqPiLVm
gameserver:dev: channelId qRja5juBIRVEgFie7FqPiLVm
gameserver:dev: id: qRja5juBIRVEgFie7FqPiLVm
gameserver:dev: channelId qRja5juBIRVEgFie7FqPiLVm

#

hit still never gets called

idle dew
#

That will always be false

brittle arch
#

what what

idle dew
#

new String("x") === "x" will always be false

brittle arch
#

._.

idle dew
#

I suspect decoder.decode might return new String(something), which is why I asked about typeof id, if that's "object", that's probably what it is

boreal flame
#

try:

(id.toString() === channel.id.toString())
brittle arch
#

oh no, it was type of string

idle dew
#

Does one of those strings have whitespace then?

brittle arch
#

uh, guess i can try to strip them

boreal flame
#

yeah

frank grail
#

just attach a debugger at this point instead of trying random logs

brittle arch
#

nope didnt work

#

if(id.trim() === channel.id.trim())

#

gameserver:dev: id: Y7TJaPFcWlMXLwRLlAsYJGPE
gameserver:dev: channelId Y7TJaPFcWlMXLwRLlAsYJGPE
gameserver:dev: id: Y7TJaPFcWlMXLwRLlAsYJGPE
gameserver:dev: channelId Y7TJaPFcWlMXLwRLlAsYJGPE

#

okay dumb question, how od i do that with vscode

#

im using vite and turborepo

boreal flame
#

I want to know too 🙂

frank grail
#

you run node scripts via vite?

#

isnt it for frontend

brittle arch
#

i think? im using turborepo

idle dew
#

My favorite config is:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Attach",
            "port": 9229,
            "request": "attach",
            "internalConsoleOptions": "openOnSessionStart",
            "skipFiles": ["<node_internals>/**"],
            "type": "node",
            "sourceMaps": true
        }
    ]
}

Can run your app with node --inspect-brk some/file.js then add a breakpoint somewhere

brittle arch
#
Uncaught TypeError TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for C:\Users\sraya\OneDrive\Documents\web_development\ruckus-rebirth\apps\gameserver\src\index.ts
    at getFileProtocolModuleFormat (internal/modules/esm/get_format:160:9)
    at defaultGetFormat (internal/modules/esm/get_format:203:36)
    at defaultLoad (internal/modules/esm/load:143:22)
    --- await ---
    at runEntryPointWithESMLoader (internal/modules/run_main:147:19)
    at executeUserEntryPoint (internal/modules/run_main:166:5)
    at <anonymous> (internal/main/run_main_module:28:49)```
#

uh

boreal flame
#

You could just iterate over the 2 strings and compare each character, and also compare length. Might tell you something

#

Will probably just show a match though lol

idle dew
#

Figuring out how to get a debugger working is well worth the time

boreal flame
#

sure

idle dew
#

Node can't run TS directly, you can probably use whatever you use to normally run your app and pass --inspect-brk to it before the file to run

brittle arch
#

kk

idle dew
#

probably I haven't used anything that you've mentioned

boreal flame
#

Vites does very complex stuff

#

The node packages all get rebuilt into ESM, there is ES module reloading accomplished somewhere

brittle arch
#

yeah okay i dont want to do this right now

boreal flame
brittle arch
#

thats another can of worms

boreal flame
#

maybe

brittle arch
#

will do this after i figure out what the hell is going on with this string

frank grail
#

could it be that one of the InputComponent.x[eid] = inputArray[1]; lines throws and is silently caught?

boreal flame
#

Seems you should be able to make it work with vite

brittle arch
#

nope

#

that worked before

boreal flame
#

Is it code that can be put on playground or reproduced with a small repro?

brittle arch
#
    
    const ents = inputQuery(world);
    for (let i = 0; i < ents.length; i++) {
      const eid = ents[i];
      // decode id
      const id : string = decoder.decode(ClientComponent.string[eid]);
      console.log("id:", id, "length", id.length);
      console.log("channelId", channel.id, "length", id.length);
      if(id.length === channel.id.length)
      {
        console.log("hit");
        // decode input
        InputComponent.x[eid] = inputArray[1];
        InputComponent.y[eid] = inputArray[2];
      }
    }```
#

gameserver:dev: id: hA5HbiMO3hzTefo9wefKECN2 length 32
gameserver:dev: channelId hA5HbiMO3hzTefo9wefKECN2 length 32

#

gameserver:dev: id: hA5HbiMO3hzTefo9wefKECN2 length 32
gameserver:dev: channelId hA5HbiMO3hzTefo9wefKECN2 length 32
gameserver:dev: id: hA5HbiMO3hzTefo9wefKECN2 length 32
gameserver:dev: channelId hA5HbiMO3hzTefo9wefKECN2 length 32
gameserver:dev: id: hA5HbiMO3hzTefo9wefKECN2 length 32
gameserver:dev: channelId hA5HbiMO3hzTefo9wefKECN2 length 32
gameserver:dev: id: hA5HbiMO3hzTefo9wefKECN2 length 32
gameserver:dev: channelId hA5HbiMO3hzTefo9wefKECN2 length 32

#

i dont fuckin know anymore

boreal flame
#
function comp(a: string, b: string) {
  if (a.length != b.length) throw new Error('length not equal')
  for (let i = 0; i < a.length; i++) {
    if (a[i]! !== b[i]!) throw new Error(`char ${a[i]} does not match char ${b[i]} at index ${i}`)
  }
}
frank grail
#

console.log("id:", id, "length", id.length);
console.log("channelId", channel.id, "length", id.length);

boreal flame
#

It will be really interesting if you can do that and it says it is OK

frank grail
#

you log id length 2x

boreal flame
#

yes

brittle arch
#

oh my christ

#

running this

boreal flame
#

console.log('hA5HbiMO3hzTefo9wefKECN2'.length) 24

#

you got 32?

brittle arch
#

OH MY GOD THE LENGHTS WER EOFF

#

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAa

#

THANKS YALL

boreal flame
#

non standard white space chars?

frank grail
#

bet \u200b

boreal flame
#

.charCodeAt(0)

brittle arch
#

YEAHHHHHH

#

// decode id
const id : string = decoder.decode(ClientComponent.string[eid]).substring(0, channel.id.length);

#

this is the fix

frank grail
#

*workaround

boreal flame
#

I think you should find what what the chars are with .charCodeAt(i) and find out where they came from

brittle arch
#

gameserver:dev: char: 0
gameserver:dev: char: 0

#

i guess char code 0?

boreal flame
#

are you sure you used the right index?

brittle arch
#

no its probably the way i encoded it

#

const encoder = new TextEncoder();
ClientComponent.string[eid].set(encoder.encode(channelId));

#

const maxStringLength = 32;
export const ClientComponent = defineComponent({ string: [Types.ui8, maxStringLength] });

boreal flame
#

well I don't know

open hollow
#

You could use something like this to print every char code, do this with both strings and you should definitely be able to see where they're different.

const debugString = (str: string) => {
    console.log(str.split("").map(x => x.charCodeAt(0)))
}
#

For VSCode debugging - you can open a "Javascript Debug Terminal" and anything you launch from that terminal VSCode will hook the debugger into. It's pretty magical.

frank grail
#

nvm just tried debugging and unfortunately that also hides some characters
but at least it would allow copying where you'd see it

boreal flame
#

is this something like an array with empty spaces that is concatenated into a string?

brittle arch
#
gameserver:dev:    83, 57, 122, 109,  66, 105, 107,  79, 103,
gameserver:dev:   119, 83,  55, 116,  85, 119,  78, 102,  83,
gameserver:dev:    56, 81,  75,  86, 114,  67,   0,   0,   0,
gameserver:dev:     0,  0,   0,   0,   0
gameserver:dev: ]
gameserver:dev: [
gameserver:dev:    83, 57, 122, 109,  66, 105, 107,  79, 103,
gameserver:dev:   119, 83,  55, 116,  85, 119,  78, 102,  83,
gameserver:dev:    56, 81,  75,  86, 114,  67,   0,   0,   0,
gameserver:dev:     0,  0,   0,   0,   0
gameserver:dev: ]
gameserver:dev: [
gameserver:dev:    83, 57, 122, 109,  66, 105, 107,  79, 103,
gameserver:dev:   119, 83,  55, 116,  85, 119,  78, 102,  83,
gameserver:dev:    56, 81,  75,  86, 114,  67,   0,   0,   0,
gameserver:dev:     0,  0,   0,   0,   0
gameserver:dev: ]
gameserver:dev: [
gameserver:dev:    83, 57, 122, 109,  66, 105, 107,  79, 103,
gameserver:dev:   119, 83,  55, 116,  85, 119,  78, 102,  83,
gameserver:dev:    56, 81,  75,  86, 114,  67,   0,   0,   0,
gameserver:dev:     0,  0,   0,   0,   0
gameserver:dev: ]
gameserver:dev: [
gameserver:dev:    83, 57, 122, 109,  66, 105, 107,  79, 103,
gameserver:dev:   119, 83,  55, 116,  85, 119,  78, 102,  83,
gameserver:dev:    56, 81,  75,  86, 114,  67,   0,   0,   0,
gameserver:dev:     0,  0,   0,   0,   0
gameserver:dev: ]
gameserver:dev: [
gameserver:dev:    83, 57, 122, 109,  66, 105, 107,  79, 103,
gameserver:dev:   119, 83,  55, 116,  85, 119,  78, 102,  83,
gameserver:dev:    56, 81,  75,  86, 114,  67,   0,   0,   0,
gameserver:dev:     0,  0,   0,   0,   0
gameserver:dev: ]
gameserver:dev: [
gameserver:dev:    83, 57, 122, 109,  66, 105, 107,  79, 103,
gameserver:dev:   119, 83,  55, 116,  85, 119,  78, 102,  83,
gameserver:dev:    56, 81,  75,  86, 114,  67,   0,   0,   0,
gameserver:dev:     0,  0,   0,   0,   0
gameserver:dev: ]
gameserver:dev: [
gameserver:dev:    83, 57, 122, 109,  66, 105, 107,  79, 103,
gameserver:dev:   119, 83,  55, 116,  85, 119,  78, 102,  83,
gameserver:dev:    56, 81,  75,  86, 114,  67,   0,   0,   0,
gameserver:dev:     0,  0,   0,   0,   0
gameserver:dev: ]
gameserver:dev: [
gameserver:dev:    83, 57, 122, 109,  66, 105, 107,  79, 103,
gameserver:dev:   119, 83,  55, 116,  85, 119,  78, 102,  83,
gameserver:dev:    56, 81,  75,  86, 114,  67,   0,   0,   0,
gameserver:dev:     0,  0,   0,   0,   0
gameserver:dev: ]
gameserver:dev: [
gameserver:dev:    83, 57, 122, 109,  66, 105, 107,  79, 103,
gameserver:dev:   119, 83,  55, 116,  85, 119,  78, 102,  83,
gameserver:dev:    56, 81,  75,  86, 114,  67,   0,   0,   0,
gameserver:dev:     0,  0,   0,   0,   0
gameserver:dev: ]```
#

yeah

boreal flame
#

hmmm

#

well I guess that's it

#

0 is the Null character apparently

#

is that the string terminator used in C?

brittle arch
#

no idea, its reading from a typed array

boreal flame
#

In C, strings (character arrays) are terminated by null character '\0' - character with value zero. In ASCII, the NUL control code has value 0 (0x00).25 Dec 2022

frank grail
#

where it pads everything to 32

boreal flame
#

that's what it is doing yeah

#

I'm pretty confident anyhow

frank grail
#

if the ids always have length 24: change maxStringLength
otherwise add an ui8 length field

or better yet: avoid strings altogether if possible

brittle arch