Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by JiMMaR · Jun 24, 2012 at 10:42 PM · javascriptyield waitforsecondsboo

Using Yield waitforseconds with boo

I've been following the walkerboystudio tutorials, but I decided that I'll try and write everything with Boo instead of unityScript [or JavaScript .. whatever you wanna call it]

in the first lab project , they call a function from inside the update() that contains Yield waitForSeconds() call , when I did that with Boo the whole function doesn't get called here's my both scripts

JavaScript:

 var numberOfClicks = 2;
 var waitTime = 2.0;
 
 function Start () {
 
 }
 
 function Update () {
     if(numberOfClicks <= 0){
         var position = Vector3(Random.Range(-7,7),Random.Range(-4,4),0);        //random positions between 2 points
         respawnTime();
         transform.position = position;                //set the object hit to this new position
         numberOfClicks = 2;
     }
 }
 
 
 function respawnTime(){
         renderer.enabled = false;
         yield WaitForSeconds(waitTime);
         renderer.enabled = true;
 }


this one works, and the next one is

Boo:

 import UnityEngine
 import System.Collections
 
 //Enemy Script
 
 class scriptEnemy (MonoBehaviour): 
     //public variables
     public numberOfClicks = 2
     public waitTime = 2.0
     
     def Start ():
         pass
         
     def Update ():
         if(numberOfClicks <= 0):
             position = Vector3(Random.Range(-7,7),Random.Range(-4,4),0)        //random positions between 2 points
             respawnTime()
             transform.position = position                //set the object hit to this new position
             numberOfClicks = 2
             
             
         
     def respawnTime() as IEnumerator:
         print ("respawn called")
         print(Time.time)
         renderer.enabled = false
         yield WaitForSeconds(waitTime)
         renderer.enabled = true
         print(Time.time)
     

This one does nothing , the whole respawnTime function/subroutine/method doesn't get called at all, if I removed the yield line , it gets called fine Any idea why is this happening ?

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image whydoidoit · Jun 24, 2012 at 10:44 PM 0
Share

I'd just like to say wow the first boo question I've seen! Interested to see the answer...

avatar image pudd1nG · Jun 24, 2012 at 10:49 PM 0
Share

try yield return new WaitForSeconds

avatar image JiMMaR · Jun 24, 2012 at 10:55 PM 0
Share

I did try "yield return new WaitForSeconds" before [found that when I was still looking for a solution] and it didn't work .. nothing happened

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Kevin Harris · Sep 02, 2012 at 04:11 AM

In Boo, like C#, you need to use `StartCoroutine()`. The documentation has an example using WaitForSeconds.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by hijinxbassist · Jun 24, 2012 at 10:53 PM

I havent gotten yield to work, but what you can do is just simply say

 WaitForSeconds(waitTime)
Comment
Add comment · Show 7 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image hijinxbassist · Jun 24, 2012 at 10:55 PM 0
Share

if you add yield before the WFS call it stops running all the code in that section, i discovered this method while converting my own script to boo

avatar image JiMMaR · Jun 25, 2012 at 03:38 AM 0
Share

I removed the yield , but it's not executing the wait part .. I get output as

-respawn called

-1.432662

-1.432662

so it's not waiting at all

avatar image hijinxbassist · Jun 25, 2012 at 03:58 AM 0
Share

is the def X()as IEnumerable ?? i have it in my script and it works

 def RespawnTime()as IEnumerable:
     
     print(Time.time)
     
     WaitForSeconds(waitTime)
     
     print(Time.time)

I have found co-routines to be very finicky in boo. I remember it took like 5 times of deleting/re-writing the same exact thing and 2 of 3 would not work. Try rewriting the def and see if it works...i know it works in my script with proper output.

avatar image hijinxbassist · Jun 25, 2012 at 04:21 AM 0
Share

Im testing on a boo script in my current project, and it isnt working...lemme test it some more and ill get back to you. Very strange since it works in my other project.

avatar image JiMMaR · Jun 25, 2012 at 08:03 PM 0
Share

yeah I did have IEnumerable [also tried IEnumerator just like the unity manual suggests] but that didn't work too here's my whole code right now http://pastebin.com/7em4GQ27 and it just prints the time twice , doesn't wait

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Why not Boo? 1 Answer

What programming language do I need to learn? 0 Answers

Can I convert unityscript to boo? 0 Answers

Closure does not work in Unity JS functions? 1 Answer

Collide detection with tag [JS] 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges