0 votes

See title. I have a dictionary which hold various data for the player's weapons in my game.

public Dictionary wpnDict = new Dictionary {};

Entries in the dictionary.

//Add entries to wpnDict. The key ID is the currently equipped weapon. The array stored within stores number of ticks between bullets, how many bullets spawn with each shot, and eventually, the animation needed.
        wpnDict.Add(0, new Array {8, 1, null});
        wpnDict.Add(1, new Array {16, 5, null});
        wpnDict.Add(2, new Array {12, 2, null});

However, when I attempt to PULL the needed data from the array, I encounter errors, here's the code.

if(plyr1BulletTicks = wpnDict[plyr1CurrWeap][0])
//Spawn bullet

And the error I receive is:

Cannot apply indexing with [] to an expression of type 'object'

What is the proper way for me to pull the array entry that I want with C#? Not having any luck finding the right syntax.

Godot version 3.4 Mono
in Engine by (207 points)

1 Answer

0 votes

Add using

using System.Linq;


if(plyr1BulletTicks == wpnDict.ElementAt(plyr1CurrWeap).Value[0]) // Use double equal
    //spawn bullet

I think you'd better use another STL types.

by (236 points)

What do you recommend?

STL type that you can access by index. like Array of Arrays, Lists, Vectors...

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 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 webmaster@godotengine.org with your username.