Search Unity

How to use yield effectively? Why the game crashed when I added it?

Discussion in 'Editor & General Support' started by flyric123, May 24, 2011.

  1. flyric123

    flyric123

    Joined:
    May 8, 2011
    Posts:
    13
    Hi, there,
    I got some problems on 'yield' function:
    The whole game crashed when I added a yield function in the Start().

    The code is
    www = WWW("file://D:\1.jpg")
    yield www

    There surely is a 1.jpg under D:\, but when I added the 'yield www', the game crashed.
    Why? Does anyone know about this?

    Thanks a lot!
     
  2. appels

    appels

    Joined:
    Jun 25, 2010
    Posts:
    2,687
    Your syntax on the url is wrong, it should be :
    www = WWW("file://D:/1.jpg")
     
  3. flyric123

    flyric123

    Joined:
    May 8, 2011
    Posts:
    13
    Oh, I think I pasted the code to here wrongly!
    It is 'www = WWW("file://D:/1.jpg")' in my script, and when I added the 'yield', the game crashed.
    Do you know why? I am kind of rookies in 'yield' function.

    Thanks!
     
  4. appels

    appels

    Joined:
    Jun 25, 2010
    Posts:
    2,687
    it should work just fine, can you post the complete code ?
     
  5. flyric123

    flyric123

    Joined:
    May 8, 2011
    Posts:
    13
    Ok, but the whole game is about 2800 lines, so I just paste the part of 'www' and 'yield' here:
    #the function of the code here is to read a path of an image from a file, then load the image based on the path. So I use the www to do the job. BTW, the script is in Boo.

    www as WWW

    Path_For_File = Application.dataPath + '/' + "Customer_Face_1.txt"
    temp_txt = ""
    try:
    using text_file = StreamReader(Path_For_File):
    temp_txt = text_file.ReadLine()
    temp_x = text_file.ReadLine()
    temp_y = text_file.ReadLine()
    except e as FileNotFoundException:
    pass

    if temp_txt == "Default" or temp_txt == "":
    Face_0.mainTexture = Default_Face_0
    Face_0_Offset.x = -0.12
    Face_0_Offset.y = -0.03
    else:
    WaitingForImage(temp_txt)
    #when I add yield www here, game crashed!
    #yield www
    Face_0.mainTexture = www.texture
    Face_0_Offset.x = single.Parse(temp_x)
    Face_0_Offset.y = single.Parse(temp_y)

    #here is the defination of WaitingForImage()
    def WaitingForImage(file as string):
    www = WWW("file://" + file)