#My json data is mixing up keys
1 messages · Page 1 of 1 (latest)
** You are now Level 2! **
Mixes which two?
So like the first question gets printed fine, but the second one has the response and answer mixed?
it mixes "R" from "A1" and "R" from "A2"
yes, but just the responses
Could you send both things as text? Unfortunately nothing immediately appears as wrong so I want to try and test it
do you mean bring the json data as text into discord because I don't know how to do that
If you copy and paste both things into Discord as separate messages that'd work
Okay
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
here you go
I assume you decode via HTTPService?
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.
k
it prints fine it must be somthing with my function\
Okay good, so we just gotta print out every value we pull from the json to ensure it's not something we don't expect
yeah
When I printed the values on the first question it responded with just on but on the second it responded with both switching the values every couple of letters
How many times is the writeResponse function being called?
It gets called once to print the question and then It gets called again to write the response
** You are now Level 3! **
I think something must be happening with the writeReponse function. Do more prints in that function to see what its asked to print and to what.
k
yeah When i call the Q.A1.R it calls both strings on the second time do you know a way around this
Do you create new buttons every time? Or are you reusing the same ones?
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
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()
thank you so much for helping me solve this problem