Else statement does not work as expected on Windows
desilva2007
Member Posts: 3
Hello everyone!
I was working on switching scenes and tried to do it with an if-else statement, such as if a player wins a level go to a specific scene and if the player loses, go to another scene.
The if part works fine without the else part. When I include the else part, and preview, the game jumps to that 'else' scene immediately.
Is there a way to fix it?
Any suggestions?
Thanks in advance!
Comments
Post a screenshot of your rules. We can't help you without seeing them. We'd just be guessing.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
As @tatiang says, a screenshot would help.
But, how does your rule know that the game is over? The rule gets checked imediately when the scene loads - at that point the win condition will still be false, and the else statement gets run.
You probably need a game state flag like game.GameOver=false, then change it to true once the level is completed.
Then you can nest your if-else into anouther rule checking for game.GameOver=True
MESSAGING, X-PLATFORM LEADERBOARDS, OFFLINE-TIMER, ANALYTICS and BACK-END CONTROL for your GameSalad projects
www.APPFORMATIVE.com
@ Hopscotch
I think I have the logic as you have it stated, but without a flag.
My game is about comparing two texts.
Here's how it looks:
Rule
if self.word is game.text
do
go to next scene
else
go to TRYAGAIN
end
where TRYAGAIN is just a different scene.
@desilva2007, so I am asuming the rule is in a button that gets pressed after the word was entered?
Do you have a "if Touch is pressed" rule around it?
If not, the the "else" part will always trigger the second the scene is loaded.
Please post a screenshot if this still does not help.
MESSAGING, X-PLATFORM LEADERBOARDS, OFFLINE-TIMER, ANALYTICS and BACK-END CONTROL for your GameSalad projects
www.APPFORMATIVE.com
@Hopscotch Can I email you my screenshot? I do not know how to upload my screenshot over here
@desilva2007, sure, i will PM you my address.
MESSAGING, X-PLATFORM LEADERBOARDS, OFFLINE-TIMER, ANALYTICS and BACK-END CONTROL for your GameSalad projects
www.APPFORMATIVE.com
You can drag an image file right into the body of a message or use the attachment/page icon in the message toolbar to embed it.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Hi, I have similar problem here. I work on windows and the problem is that when the if statement is true, the do block runs as well as the else block too.
When the if statement is false, it ignores the do block and runs else block properly. What am I doing wrong?
So, when the if statement is true I want it to increase score attribute by 10, else I want the lives arrtibute to increase by 1. The thing is when I preview it, if the statement is true (comparing strings to check if answer is true), the score gets increased and the lives decreased. But when the if statement is false, the lives attribute decreases. Any help?
@arteewtf Try placing a condition in your else section. In other words, "else if something = something, then something."
Mathtap.com (Android) | Fridgemanager.com (Android) | Breakoutofspace.com (Android)
I compare strings so cannot say if not. I did although added an integer atrribute 0 and change it to 1 when the if statement is true. Then I added an extra if in the else block saying that if this attribute is 0 decrease lives. But I had the same result.
@arteewtf So if you compare strings, can you use the "is not" in the strings dropdown instead of "is"?
Mathtap.com (Android) | Fridgemanager.com (Android) | Breakoutofspace.com (Android)
@arteewtf The quickest way to resolve this is going to be to upload your project folder to a file-sharing site (it's best to .zip it first) and then post the download link here. It could be any number of things causing this issue. I could suggest a bunch of troubleshooting steps to find the problem but it's easiest if I can see how your game is set up.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
There isn't a "is not" in dropdown for strings. Only: is, contains, ends with, begins with. At leastn on windows version. Now I am trying to install mac on virtual box to check if it runs there. I will compress the project and upload it somewhere for you to check it, but it will take me a while @tatiang . Thanks in advance
https://dropbox.com/s/gzkifrsl5s7u3wf/quiz_test2.zip?dl=0
I uploaded the project folder. Ignore the timer thing, I haven't bothered with it yet Also, check the table for witch the correct answer is. Every row contains: columns1-4 -> 4 possible answers, column 5 is the question and column 6 is the correct answer.
@arteewtf Your "GameplayQuestions" table is 1x1, and empty.
Mathtap.com (Android) | Fridgemanager.com (Android) | Breakoutofspace.com (Android)
@Summation I don't know why you see it empty, I download it from the above link and open it and I see it. It's a 6x6. Maybe because the questions are in greek? I reupload it. Try to check it now plz. Now, It only runs correct for the first question and do the same I explained above for the rest questions. Here's the link again: https://dropbox.com/s/gzkifrsl5s7u3wf/quiz_test2.zip?dl=0
@arteewtf I still see a 1x1 empty table. Are you using windows or mac?
Here is what I see:
Mathtap.com (Android) | Fridgemanager.com (Android) | Breakoutofspace.com (Android)
I am using Windows. Here is the XML file for the table from my project: https://dropbox.com/s/vbmmikzfwh5xr0n/id725493.zip?dl=0
It's not really my questions, I just put question1, question2 1 etc.