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

phy_collision_x/y is marked as real, but is an array #4532

Closed
Glim888 opened this issue Jan 27, 2024 — with GM Bug Reporter · 7 comments
Closed

phy_collision_x/y is marked as real, but is an array #4532

Glim888 opened this issue Jan 27, 2024 — with GM Bug Reporter · 7 comments
Assignees
Labels
documentation Improvements or additions to documentation are required by this issue
Milestone

Comments

@Glim888
Copy link

Glim888 commented Jan 27, 2024

Description

phy_collision_x/y is marked as real, but is an array

3a03bac0-6116-42d3-bc57-5f4a87cbc4d9

@gm-bug-reporter gm-bug-reporter bot added the documentation Improvements or additions to documentation are required by this issue label Jan 27, 2024
@stuckie stuckie added this to the 2024.4 milestone Jan 29, 2024
@DiasFranciscoA DiasFranciscoA moved this from Todo to In Progress in Team Workload Jan 31, 2024
@github-project-automation github-project-automation bot moved this from In Progress to Done in Team Workload Jan 31, 2024
@Appley-Apple
Copy link

I don't know how the GML type system works exactly but this appears to be more than just a documentation issue. On the current beta version I am unable to use array functions on phy_collision_x or phy_collision_y, however I can still index them as if they are arrays. Also, typeof(phy_collision_x) returns "number", not "array" (same for phy_collision_y).

@Glim888
Copy link
Author

Glim888 commented Feb 11, 2024

image

This is how I use it in RT v2023.11.1.160 to avoid crashes.

@Glim888
Copy link
Author

Glim888 commented Feb 11, 2024

I would like to add an additional error about the phy_collision_points.

If you destroy the instance in the same collision step. Then the phy_collision_points became null (silent crash)

collision event:
instance_destroy();
show_debug_message(phy_collision_x[0]);
--> crash

@DiasFranciscoA

@Appley-Apple
Copy link

image

This is how I use it in RT v2023.11.1.160 to avoid crashes.

Is there a way to handle multiple collision points? Sometimes I get 2 collision points and I'd like to know where both of them are, currently phy_collision_x and phy_collision_y are just numbers so they only tell you about a single point.

@Glim888
Copy link
Author

Glim888 commented Feb 11, 2024

Nah it's an array, but you need to check how long the array is.

YYBartT added a commit to YoYoGames/GameMaker-Manual that referenced this issue Mar 5, 2024
YoYoGames/GameMaker-Bugs#4532
* Fixed on phy_collision_x and phy_collision_y pages
* Moved note about "collision event only" to a snippet and inserted on all function pages
* Explicitly added "Collision Event" to the examples to indicate context
* On phy_collision_points page: "between the two objects in the collision" => "between the two instances in the collision"
* A few typo fixes here and there
YYBartT added a commit to YoYoGames/GameMaker-Manual that referenced this issue Mar 6, 2024
YoYoGames/GameMaker-Bugs#4532
* Updated the pages of all collision event variables again:
  * Inserted "Note" snippet on each page to explain built-in arrays aren't "real" arrays
  * Syntax changed to "builtin_array[index]", return type kept as "real", since - in theory - you can only access an array through an array lookup and that array lookup *does* return a real (omitting the subscript is allowed for backward compatibility)
  * Removed semicolons ";" at the end of the syntax line as these are expressions, rather than statements
* Updated manual pages of other built-in global arrays as well. All of these pages should be updated by this commit.
* Changed "Note" snippet about built-in arrays not being "real" arrays: "read" -> "access"
@YYBartT
Copy link

YYBartT commented Mar 6, 2024

Built-in arrays aren't "true" arrays, a consequence of that is that they cannot be used with the array functions. The syntax meant to be used is the array syntax with the subscript operator:

var _val = builtin_array[index];  // Looks up value at index "index"

The other syntax:

var _val = builtin_array;  // Looks up value at index 0, does not assign a reference to the built-in array to _val

is supported for backward compatibility, as confirmed by @rwkay.
I updated the manual pages to use the first syntax, since that syntax is the one that avoids confusion (other manual pages for built-in array variables, such as instance_id and view_wport also use this syntax). This syntax does return a real in case of the physics collision arrays, since the element at index 0 in any of those arrays is of type real. Another consequence is that, because of how the second syntax works, typeof(builtin_array) returns the type of the first element in the array (which is "number" in the case of phy_collision_x, phy_collision_y, phy_col_normal_x and phy_col_normal_y).

@YYBartT YYBartT moved this from Done to Ready for QA in Team Workload Mar 6, 2024
@alicemoretti
Copy link
Contributor

Verified fixed in the current Beta version of the Manual.

Thank you.

@alicemoretti alicemoretti moved this from Ready for QA to Verified in Team Workload Apr 8, 2024
gurpreetsinghmatharoo pushed a commit to YoYoGames/GameMaker-Manual that referenced this issue Aug 8, 2024
YoYoGames/GameMaker-Bugs#4532
* Fixed on phy_collision_x and phy_collision_y pages
* Moved note about "collision event only" to a snippet and inserted on all function pages
* Explicitly added "Collision Event" to the examples to indicate context
* On phy_collision_points page: "between the two objects in the collision" => "between the two instances in the collision"
* A few typo fixes here and there

(cherry picked from commit e1a58c0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation are required by this issue
Projects
Status: Verified
Development

No branches or pull requests

6 participants