code.org - Is there a way to get the current screen id in App Lab? - Stack Overflow

I want to be able to create an if block based on my current screen ID. It tried the getScreen thing but

I want to be able to create an if block based on my current screen ID. It tried the getScreen thing but it doesn't work because it says the variable hasn't been defined yet.

if (getScreen() == "Start"){
playSound("trendsetter-mood-maze-main-version-02-53-1004--AudioTrimmer-.mp3", true);
}

I'm really confused and I have to submit my project in a week. Does anyone know how to do this?

I want to be able to create an if block based on my current screen ID. It tried the getScreen thing but it doesn't work because it says the variable hasn't been defined yet.

if (getScreen() == "Start"){
playSound("trendsetter-mood-maze-main-version-02-53-1004--AudioTrimmer-.mp3", true);
}

I'm really confused and I have to submit my project in a week. Does anyone know how to do this?

Share Improve this question asked Mar 17 at 19:06 Tanicia SajithTanicia Sajith 1
Add a comment  | 

2 Answers 2

Reset to default 0

As of 2025, there isn't a built-in method to get the current screen ID in Code.. A simple workaround is to create an array of screen names and use an integer to track the current screen.

An example implementation:

var screens = ["screen1", "screen2"];
var position = 0;

position += 1;  // Increment position

// Ensure position is within bounds
if (position < screens.length) {
  if (screens[position] == "screen2") {
    console.log("We are on screen2!");
  }
} else {
  console.log("Out of bounds!");
}

Nevermind! I found a better, more code efficient way to do it:

var screenId = "Start";
function curS (string){
  screenId = string;
  setScreen(screenId);
} // curS stands for currentScreen

Now each time I want to use setScreen I can replace it with curS so it also updates my screenId and I can use screenId in place of the getScreen I had tried in my initial code.

if (screenId == "Start"){
 playSound("trendsetter-mood-maze-main-version-02-53-1004--AudioTrimmer-.mp3", true);
}

Thank you everyone for the help though :)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744539935a4579662.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信