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 12 Answers
Reset to default 0As 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条)