This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

extends Area2D

var list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

func onPlayerLaserarea_entered(area):

if area.is_in_group("enemies"): #ignore this
    area.take_damage(1). #ignore this
    queue_free() #ignore this


var item

item = list[rand_range(0, list.size())]

print(round(rand_range(0, list.size())))
in Engine by (17 points)

2 Answers

0 votes

So, there's not really a need to have an Array with the values 0, 1, 2, etc. since those are already the indices of the Array. Instead, the values should be the images themselves. So like:

var list = [preload("image0.png"), preload("image1.png"), preload("image2.png")...
by (8,580 points)

Also how do i can show the different images in a random order in the screen when something is destroyed.

func onPlayerLaserarea_entered(area):

if area.isingroup("enemies"):
free() #when it destroy to show a ramdom image in a random place

0 votes

Also you can create a dictionary and use load to reduce the use of memory, but impacting performance. Check what fits better for you and read documentation about preload and load before trying this solution.

by (258 points)
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.