Search Unity

Loop doesn't work as written?

Discussion in 'Scripting' started by pivotraze, Nov 29, 2012.

  1. pivotraze

    pivotraze

    Joined:
    Feb 4, 2012
    Posts:
    593
    Code (csharp):
    1.  
    2. def JumpScare() as IEnumerator:
    3.         Debug.Log("Started Co")
    4.         while timeChange < 10:
    5.             Debug.Log("Break")
    6.             if bIamRunning == true:
    7.                 Debug.Log("Running TimeChange")
    8.                 timeChange = 0
    9.                 Debug.Log("Set time to 0")
    10.                 yield WaitForSeconds(0.1)
    11.                 Debug.Log("Waited for .1 secs")
    12.             elif bIamRunning == false:
    13.                 Debug.Log("Waiting for a sec...")
    14.                 yield WaitForSeconds(1)
    15.                 Debug.Log("waited.")
    16.                 timeChange += 1
    17.                 Debug.Log("Added one to timeChange")
    18.         if timeChange >= 10:
    19.             audioPlayed = false
    20.             timeChange = 0
    21.             Debug.Log("Can play audio again!")
    22.         else:
    23.             pass
    24.  
    And where the coroutine gets called:
    Code (csharp):
    1.  
    2. if flashObj.light.enabled == false:
    3.             if bIamRunningF == false:
    4.                 StartCoroutine("FlashlightOffSanity")
    5.             else:
    6.                 pass
    7.        
    8.         elif Monsterd.renderer.isVisible == true or dist < 5:
    9.             if dist > 100:
    10.                 bMonsterVisibleRange = false
    11.             else:
    12.                 bMonsterVisibleRange = true
    13.             if bIamRunning == true:
    14.                 pass
    15.             else:
    16.                 StopAllCoroutines()
    17.                 StartCoroutine("ISeeTheMonsterMan")
    18.                 if (audioPlayed == false) and (dist < 20):
    19.                     scarySound.audio.Play()
    20.                     audioPlayed = true
    21.                     StartCoroutine("JumpScare")
    22.                 else:
    23.                     pass
    24.  
    Basically, it works the first time I look at him, and counts up as planned. However, if I look at the monster one more time, the flashlight DOES reset to 0, but when I look away it doesn't restart counting up. Why? :\
     
  2. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,537
    Don't make us read your code just to understand what you're asking.

    minus the code you basically just say:

    Really? who is him? How are you looking at him? What "counts up"? What is the monster? What is the flashlight, and what does reseting to 0 mean? And when you look away from what, what starts counting up?

    Why?
    WHY?
    How in the hell do we know!?
     
  3. pivotraze

    pivotraze

    Joined:
    Feb 4, 2012
    Posts:
    593
    I don't have a name at the monster

    Occlusion culling. When the screen renders him, you are looking at him. As soon as he is behind an object or not being looked at, he is no longer rendered, effectively, he is not being looked at.

    ... A timer.
    It doesn't really matter.

    A spotlight.

    If you read the code, the timer = 0.

    Look away from the monster, the timer goes up.

    You read the code. This IS the scripting forum.
     
  4. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    I was looking at that code thinking, wtf is this S***!?

    Then im like, oh its boo... well what an ugly pos language that is.

    Thats where my interest in this thread ended.
     
  5. Loius

    Loius

    Joined:
    Aug 16, 2012
    Posts:
    546
    Whoa, Boo.

    Typo?

    I don't see timeChange set anywhere before JumpScare is called (don't know if Boo autodeclares or anything). I think you'd have to set it before starting the coroutine.

    Also - timeChange is too nondescript of a variable name for me to understand what it's doing. :S

    I had to write in stupid Python to fix Blender's broken FBX exporter. ... I can look at Boo and almost understand it :(
     
    Last edited: Nov 29, 2012
  6. pivotraze

    pivotraze

    Joined:
    Feb 4, 2012
    Posts:
    593
    Show's your open mind.

    This is where my interest of any games you make in the future end.

    My favorite language in Unity. Only language I'll use.

    bIamRunningF actually isn't :) It's to let me know between different bools. One is bIamRunning, bIamRunningS, and bIamRunningF. While they may have little meaning to you, I know exactly what each is for :)

    It's declared globally in the beginning of the script, it just isn't shown :)

    Originally, I used it to check between two Time.time checks. Now, it's just not changed. Basically, it is a timer variable.


    Outside of Unity, I will only write in Python because I believe it is the best language out there.

    The conventions of Python, and in effect Boo, are beautiful.
     
  7. Loius

    Loius

    Joined:
    Aug 16, 2012
    Posts:
    546
    I mean, each time -
    Code (csharp):
    1.                 if (audioPlayed == false) and (dist < 20):
    2.                     scarySound.audio.Play()
    3.                     audioPlayed = true
    4.  
    5. // Don't you need to set timeChange to zero here?  Otherwise it's undefined if JumpScare has ever run.  The timer is resetting to zero because, in JumpScare, it's set to zero if it's greater than 10.
    6.  
    7.                     StartCoroutine("JumpScare")
    8.                 else:
    9.                     pass
    I will say this for Python/Boo-style syntax - it's much, much more gentle on the eyes than the Lisp-derivative I had to use in school. I do favor languages with absolutely no claim on whitespace, though. :)
     
  8. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    I know enough languages without getting into another somewhat inadequate looking one that ill never even consider using.

    Good for you choosing the underdog.

    Its not like youve shown any yet anyway, so no loss there
     
    Last edited: Nov 29, 2012
  9. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Please refrain from posting antagonistic messages that add nothing to the topic, thanks.

    --Eric