I'm making a card game setup using Godot. I'm learning the engine and programming as I go along. Not really making a game, rather, converting a research workshop of ours that uses cards into a digital variant. There are 17 cards in a dictionary with paths to texture, name, etc which I have shuffled, with 2 scripts one on root node and one for drag/drop.
The program is simple, you pick cards form a deck and place them in shuffled placeholders like solitaire. The way I approached it was to make
TextureRect nodes as placeholders on the screen then a basic drag and drop script attached to them that changes the resource path. Problem I'm facing is once you drag and drop, the texture is duplicated (used the basic drag/drop script from Godot assets). What should happen is after dropping its removed from the previous placeholder and if it took another cards place that card is sent to the 'deck'. This is the drag script so far:
var GLOBAL = preload("res://script/Exercise1.gd").new()
var default = "res://gfx/Empty.png"
func get_drag_data(_pos): # make a preview of card while dragging
var drag = TextureRect.new()
drag.texture = texture
drag.rect_scale = Vector2(0.5, 0.5)
if drag.texture.resource_path != default:
func can_drop_data(_pos, data):
func drop_data(_pos, data):
texture = data
I imagine it as a
check_table() function in the main script, which compares the textures in the placeholders to an array
item_cards dynamically populated for the current shuffled cards. Function checks for duplicates after dragging, if any removes them, then if a card was replaced while dragging that card is sent back to deck to be dragged out again later. I can't really proceed into making
check_table() because it won't let me reference
item_cards. Did this for a test:
The function is being called fine, if I put in a
print("something") in the function that works perfectly. But I can't reference any variables outside of the function this way. I know
item_cards is not empty but I get this error every time:
Invalid get index '0' (on base: 'Array').
Definitely doing something wrong here. Maybe my whole using textures is the wrong approach? I've gotten this far though lol
Any help is much appreciated, thank you.