Search code examples
arrayssyntax-errorgodot

'Invalid operands "Array" and "int" for "*" operator' in Godot


I am new in Godot and I'm getting this error when I made this array:

var RL = [' '] + [atlas_coord_0[5]] * 5 + [atlas_coord_0[3]] * 5 + [atlas_coord_0[1]] * 10 * 5 + [main_block] * 25 * 5 + [atlas_coord_0[2]] * 25

I don't know how to fix this. Thanks for all your help! P.S. Don't hate on me pls


Solution

  • You're basically multiplying arrays by ints I see two things that you could be trying to do.

    If by multiplying the arrays you search to repeat the array such as

    [value] * 2 = [value, value]
    

    I'm sorry to tell that a quick search revealed that there's no shortcut for this in gdscript (I'm not 100% sure please edit if I'm wrong). You can use a for loop.

    If you just want to multiply the content of the array, well since it's a single value then you can move the closing square bracket after the multiplication.