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

Cannot have a name shared by a static and local variable in function #4449

Closed
gm-bug-reporter bot opened this issue Jan 23, 2024 · 4 comments
Closed
Assignees
Labels
build-bug Bugs when compiling projects inside GameMaker documentation Improvements or additions to documentation are required by this issue gmrt project This issue has a sample project attached

Comments

@gm-bug-reporter
Copy link

Description

There are cases where you may want to either create a static or create a local variable in a function. If you want to do this in the Beta, they cannot share a name (despite only one ever being initialised, not both). This is changed functionality from the stable build.

Steps To Reproduce

Create a script with a conditional that branches into either creating a static or a local variable. Make sure they have the same name. Try to do anything with that variable and the game will crash, i.e.:

#macro STATIC_FUNCTION true
function Script1(){
if (STATIC_FUNCTION) {
static _result = {
x: 0,
y: 0
}
}
else {
var _result = {
x: 0,
y: 0
}
}
return _result;
}

cc822a2d-30ea-4bac-963c-990e4e3adaf0

@gm-bug-reporter gm-bug-reporter bot added build-bug Bugs when compiling projects inside GameMaker project This issue has a sample project attached labels Jan 23, 2024
@stuckie stuckie added documentation Improvements or additions to documentation are required by this issue gmrt labels Jan 23, 2024
@stuckie stuckie moved this from Todo to Backlog in Team Workload Jan 23, 2024
@rwkay
Copy link

rwkay commented Jan 23, 2024

This is not a bug - statics and locals cannot have the same name

@rwkay rwkay closed this as completed Jan 23, 2024
@github-project-automation github-project-automation bot moved this from Backlog to Done in Team Workload Jan 23, 2024
@RefresherTowel
Copy link

This is not a bug - statics and locals cannot have the same name

Even though only one can exist at any time? In my example, the static is only created if a macro is set to a certain value, otherwise a local variable is created instead of the static, so there's either a static variable or a local, not both together. I would assume that if I'm not creating the static, then the local should be able to use the name?

@rwkay
Copy link

rwkay commented Jan 24, 2024

statics are hoisted from the declaration so it would be created no matter what - the hoisting happens before the optimizer would remove the if part of the if..else.

All statics are declared at the top of the function and do not participate in code flow.

@iampremo iampremo closed this as not planned Won't fix, can't repro, duplicate, stale Jan 24, 2024
@RefresherTowel
Copy link

Hahaha, ok, I'll let Alynne know because Input is using that behaviour.

@gurpreetsinghmatharoo gurpreetsinghmatharoo added build-bug Bugs when compiling projects inside GameMaker and removed build-bug Bugs when compiling projects inside GameMaker labels Mar 7, 2024
@gurpreetsinghmatharoo gurpreetsinghmatharoo self-assigned this Apr 19, 2024
@gurpreetsinghmatharoo gurpreetsinghmatharoo moved this from Done to Backlog in Team Workload Apr 24, 2024
@gurpreetsinghmatharoo gurpreetsinghmatharoo moved this from Backlog to Ready for QA in Team Workload Apr 26, 2024
gurpreetsinghmatharoo added a commit to YoYoGames/GameMaker-Manual that referenced this issue May 6, 2024
* develop: (62 commits)
  docs(feature): GPU texture compression YoYoGames/GameMaker-Bugs#5495
  docs(feature): Review PR #117
  docs(feature): GPU texture compression YoYoGames/GameMaker-Bugs#5495
  docs(general): Fix gamepad axis and button constant links YoYoGames/GameMaker-Bugs#5134
  docs(general): Fix code in example of asset_get_index
  docs(general): debug_event note on memory usage YoYoGames/GameMaker-Bugs#5649
  docs(feature): GPU Hardware Texture Compression YoYoGames/GameMaker-Bugs#5495
  docs(general): Made it clearer that bbox values are +1 from sprite bbox, linked to on bbox_ var pages YoYoGames/GameMaker-Bugs#5101
  docs(general): Manual overview page for "Surfaces" doesn't mention freeing them after use YoYoGames/GameMaker-Bugs#5622
  docs(feature): Manual page for "wallpaper_set_config()" contains spelling error in code example YoYoGames/GameMaker-Bugs#5621
  docs(general): Document that static variables cannot be defined conditionally YoYoGames/GameMaker-Bugs#4449
  docs(general): Description error for ds_queue_tail() YoYoGames/GameMaker-Bugs#5500
  docs(general): Draw Sprite sub-image mistake fix YoYoGames/GameMaker-Bugs#5565
  docs(general): mentioned Ctrl + Comma and Ctrl + Period for workspace overview navigation on macOS YoYoGames/GameMaker-Bugs#5595
  docs(general): updated shortcuts CSS style, workspace navigation dirs set to 4 YoYoGames/GameMaker-Bugs#5595
  final fix
  fixes for pushing to s3
  fixes for pushing to s3
  fixes for pushing to s3
  adding some logging
  ...
gurpreetsinghmatharoo added a commit to YoYoGames/GameMaker-Manual that referenced this issue Aug 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build-bug Bugs when compiling projects inside GameMaker documentation Improvements or additions to documentation are required by this issue gmrt project This issue has a sample project attached
Projects
Status: Ready for QA
Development

No branches or pull requests

5 participants