Following this tutorial (which is made in Godot 3.1, if it matters):

If you skip ahead to somewhere between 16:00 - 19:00, it's the LootSelector function. You can see his and this is mine:

func LootSelector():
	for i in range(1, loot_count + 1):
		randomize()
		var loot_selector = randi() % 100 + 1
		var counter = 1
		while loot_selector >= 0:
			if loot_selector <= InventoryImport.loot_data[location]["Item" + str(counter) + "Chance"]: ### This is where it gets mad ###
				var loot = []
				loot.append(InventoryImport.loot_data[location]["Item" + str(counter) + "Chance"])
				randomize()
				loot.append((int(rand_range(float(InventoryImport.loot_data[location]["Item" + str(counter) + "MinQ"]), float(InventoryImport.loot_data[location]["Item" + str(counter) + "MaxQ"])))))
				loot_dic[loot_dic.size() + 1] = loot
				break
			else:
				loot_selector = loot_selector - InventoryImport.loot_data[location]["Item" + str(counter) + "Chance"]
				counter = counter + 1
	print(loot_dic)

I believe I copied it perfectly (with a few minor adjustments), but it still thinks I'm comparing apples and oranges. I tried getting rid of str(), and it gets mad. I tried using int() and it gets mad. I tried using float() and it gets really mad.

I feel like this is going to be a stupid easy thing I overlooked. Insight would be much appreciated because this is a long tutorial series and I don't want to trip and fall this early on.

  • I haven't tried the tutorial or looked at the rest of the code, but here's a quick guess...

    In the line:

    if loot_selector <= InventoryImport.loot_data[location]["Item" + str(counter) + "Chance"]:

    loot_selector is an int (random number from 1 to 100). If it's complaining about int and string with <=, then the loot_data must be returning a string.
    loot_data is filled from a json file. Some parts are strings, some are numbers.
    Have a look in the json file and look for the Item1Chance, Item2Chance, etc lines.

    Make sure those lines don't have quotes around the number. If it looks like this:

    "Item1Chance": "80",

    then change it to:

    "Item1Chance": 80,

    But as I said, I haven't tested it myself.

I haven't tried the tutorial or looked at the rest of the code, but here's a quick guess...

In the line:

if loot_selector <= InventoryImport.loot_data[location]["Item" + str(counter) + "Chance"]:

loot_selector is an int (random number from 1 to 100). If it's complaining about int and string with <=, then the loot_data must be returning a string.
loot_data is filled from a json file. Some parts are strings, some are numbers.
Have a look in the json file and look for the Item1Chance, Item2Chance, etc lines.

Make sure those lines don't have quotes around the number. If it looks like this:

"Item1Chance": "80",

then change it to:

"Item1Chance": 80,

But as I said, I haven't tested it myself.

    Kojack
    Okay, I opened up the json and the numbers were counted as strings. It's not throwing any errors and data is being generated. I will continue to the third function and see if it holds up (pretty sure it will).