The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

It runs then closes

This is my code:

ctrl1.getnode("Question").bbcodetext = "[center]" + questions.keys()[chosen] + "[/center]"

Godot version 4.0.3
in Engine by (79 points)

I assume questions is a Dictionary? What keys does it contain? What's the value of chosen at the time of the error?

Normally, I'd expect some sort of Invalid get index 'x' error on a Dictionary rather than an out of bound error...

--- Edit ---

Ah, right, the result of keys() IS an array - hence the array oriented error...

here is my dictionary array.

I declared it as
var questions: Dictionary #To Store the Questions

https://drive.google.com/drive/u/1/folders/1cng-solANvBjkpoRB_a7Jrwjlg3lS1di

1 Answer

0 votes
questions.keys()[min(chosen,len(questions)-1)]

You can use this for an easy fix. Basically let say we have this : arr = ["apple","banana"] then arr[1] would be equal to "banana" and if you tried to do arr[2] you get a error like that.

by (600 points)

I still get the same error

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.