#My json data is mixing up keys

1 messages · Page 1 of 1 (latest)

fringe tree
#

I have a json string that is being converted into a json file but whenever I call the first respones its fine but when I call the second ones it mixes the two

If you need more info just ask

sterile houndBOT
#

studio** You are now Level 2! **studio

sharp birch
#

Mixes which two?

So like the first question gets printed fine, but the second one has the response and answer mixed?

fringe tree
sharp birch
fringe tree
sharp birch
fringe tree
#

Okay

fringe tree
#

JSON: {
"setup": [
[
[
"Hello Happy",
{
"Q": "Do you like bread",
"A1": {
"A": "Yes",
"R": "Awsome, me too"
},
"A2": {
"A": "No",
"R": "Boo, you suck"
}
},
"okay next question",
{
"Q": "What about cheese",
"A1": {
"A": "Yes",
"R": "Neat, I do too"
},
"A2": {
"A": "No",
"R": "Eww, you disgust me"
}
}
]
]
]
}

#

CODE: function module.askQuestion(chapter : number, dialogueCounter : number, character : string)
option.Visible = true

local charNum = characterNumber(character)

local Q = data.setup[chapter + 1][charNum][dialogueCounter + 1]
local answered = false

option1.Text = Q.A1.A
option2.Text = Q.A2.A

writeResponse(Q.Q, 0, 0.05)


for i, v in pairs(buttons) do
    v.MouseButton1Up:Connect(function()
        if v.Name == option1.Name then
            option.Visible = false
            print(Q.A1.R)
            writeResponse(Q.A1.R, 2)
            answered = true
        elseif v.Name == option2.Name then
            option.Visible = false
            print(Q.A2.R)
            writeResponse(Q.A2.R, 2)
            answered = true
        end
    end)
end

while answered == false do
    wait()
end

end

sharp birch
fringe tree
sharp birch
# fringe tree yes

I'm not super sure I can find any immediate issue. You should make sure the decode didn't mess up anything by printing it immediately after you decode it.

fringe tree
#

k

fringe tree
sharp birch
fringe tree
#

yeah

fringe tree
sharp birch
fringe tree
sterile houndBOT
#

studio** You are now Level 3! **studio

sharp birch
fringe tree
#

k

fringe tree
sharp birch
fringe tree
#

reusing the same ones

sharp birch
# fringe tree reusing the same ones

Ah.

So because you're not disconnecting these connections after you make them, they'll still fire.

So the first click is fine, but after the first, there are now two connections to the same button, so two pieces of code run

sharp birch
# fringe tree how do I diconnect it

So :Connect returns a RBXSignalConnection object. By taking this and doing :Disconnect, you ensure that the code in that connection will no longer be run.

local connection = button.Activated:Connect(function()
  print("Pressed!")
end)
connection:Disconnect()
fringe tree