How to End Looping Scripts

Description: Internal scripting system of SMBX-38A Engine based on the simple VB-like language
Moderators: Lx Xzit, Yoshi021, 5438A38A, Semi-moderatos, Moderators

Yoshi021 M
Topic author, Moderator
Moderator
Avatar
Yoshi021 M
Topic author, Moderator
Moderator
Age: 22
Reputation: 170
Posts: 693
Joined: 15 Feb 2016
Location: Yoshi's Island

Post #1by Yoshi021 » 15 May 2016, 2:16

phpBB [youtube]

Original link: https://www.youtube.com/watch?v=mKlPmxV8JgA&feature=youtu.be


So in the video I have a level where you have to hit all the blocks in order to advance. What I did was have a variable "blocks" set to 20. Then I made an event that will subtract 1 from the variable and trigger a script.

Code: Select all

If val(Blocks)=0 Then
  call TCreate("Lock", 0)
End if

Event "Lock" will hide the lock that is blocking the exit and play a sound effect. The problem with this is that when I trigger the script, it will continuously play the sound effect. How do I change the script so it only plays the sound effect once?
Last edited by Yoshi021 on 17 May 2016, 15:34, edited 1 time in total.
Links
ImageImageImage
Image
Image
"Going to University is FUN!" :pardon:

Erwill M
Count
Count
Avatar
Erwill M
Count
Count
Age: 24
Reputation: 189
Posts: 295
Joined: 29 Nov 2015

Post #2by Erwill » 15 May 2016, 13:06

Is your script is in loop ?

Yoshi021 M
Topic author, Moderator
Moderator
Avatar
Yoshi021 M
Topic author, Moderator
Moderator
Age: 22
Reputation: 170
Posts: 693
Joined: 15 Feb 2016
Location: Yoshi's Island

Post #3by Yoshi021 » 15 May 2016, 17:31

How do I check if it is in loop?
Links
ImageImageImage
Image
Image
"Going to University is FUN!" :pardon:

Sambo M
Count
Count
Avatar
Sambo M
Count
Count
Age: 25
Reputation: 15
Posts: 264
Joined: 27 Jun 2014

Post #4by Sambo » 16 May 2016, 2:55

It must be in loop if the sound effect plays constantly.
Does the sound effect play for the whole test, or just after all the blocks are hit?
If it happens for the whole test, I don't know enough about this to help you.

If it just happens after all the blocks are hit, this is because Blocks = 0 for EVERY loop after all the blocks are hit, so it triggers the event on EVERY frame. Changing the value of Blocks to -1 (or anything other than 0) after triggering the event should fix the problem:

Code: Select all

If val(Blocks)=0 Then
  call TCreate("Lock", 0)
  val(Blocks) = -1
End if

Please note that I am not familiar with TeaScript, so the syntax I gave you might not be correct.
Image
Current Project:
Image

Yoshi021 M
Topic author, Moderator
Moderator
Avatar
Yoshi021 M
Topic author, Moderator
Moderator
Age: 22
Reputation: 170
Posts: 693
Joined: 15 Feb 2016
Location: Yoshi's Island

Post #5by Yoshi021 » 17 May 2016, 4:23

Code: Select all

If val(Blocks)=0 Then
  call TCreate("Lock", 0)
  val(Blocks)=-1
ElseIf val(Blocks)=-1 Then
  Text(2).text = "BLOCKS REMAINING 0"
End if

Thanks, it does work.
Links
ImageImageImage
Image
Image
"Going to University is FUN!" :pardon:


Return to “TeaScript”

Who is online (over the past 5 minutes)

Users browsing this forum: 1 guest