最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin3浏览0评论

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 :)

发布评论

评论列表(0)

  1. 暂无评论