Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug lesson 18-practice #930

Open
Joojoan opened this issue Feb 28, 2024 · 1 comment
Open

Bug lesson 18-practice #930

Joojoan opened this issue Feb 28, 2024 · 1 comment
Labels
bug Something isn't working as intended

Comments

@Joojoan
Copy link

Joojoan commented Feb 28, 2024

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the bug:

  1. Go to 'lesson 18- creating arrays-practice 2-Selecting Units'
  2. write code:
    func run():
    select_units([1,0])
    select_units([5,1])
    select_units([4,2])
    select_units([0,3])
    error: Unit in cell (1,0) not selected

Expected behavior
Since it seems to identify the other cells as selected, it should see that as selected too

Screenshots

Information about your device (please complete the following information):

  • Operating System: [Windows 11]
  • Browser: [Firefox]
@Joojoan Joojoan added the bug Something isn't working as intended label Feb 28, 2024
@baetup
Copy link

baetup commented Mar 24, 2024

This is not a bug. You have 2 weird things in your code.
This is the code that is responsible for selecting the units in the background of the live editor :

func select_units(cells: Array) -> void:
	selected_units.clear()
	for cell in cells:
		if cell in units:
			selected_units.append(cell)
	update()

You did not need to know this to actually complete the exercise but its better to show you.
What your code does is to call the func 4 times with 4 different arrays instead of doing it only once. Your code would have worked if the code above would not have had selected_units.clear() but this is beyond the purpose of this explanation.

select_units([1,0])
select_units([5,1])
select_units([4,2])
select_units([0,3])

Instead of this try calling it in a proper manner something like : select_units([Vector2(x, y), Vector2(x, y), Vector2(x, y), Vector2(x, y)]).

Second thing you understood wrong is that you're trying to call select units with an array containing simple numbers as each index instead of a Vector2 which holds coordinates. Please revisit some of the chapters prior to Lesson 18 for a better understanding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working as intended
Projects
None yet
Development

No branches or pull requests

2 participants