|
I've been using a jpeg encoder to take a screenshot of my game. The function which encodes the screenshot, aptly named EncodeScreenshot(filepath: String) is a generator function that is it contains a yield statement. The same javascript contains another function, getFilepath() which returns the filepath where the screenshot is stored. From my gui script (written in C sharp), I can call getFilepath, no problem. But when I try to call EncodeScreenshot(filepath), it doesn't appear to call the function. I have Debug.Log statements inside the function, and before and after the function call. The before and after statements print, but not the one inside the function. On the other hand, if I write a test OnGui into the Screenshot script, the function saves the screenshot to the correct location. What is happening? Why does one function call work and not the other? My wild guess is that it has something to do with the way generator functions work. GUI Code abridged Screenshot Code in full
(comments are locked)
|
|
In your getScreenshot C# method, you need to wrap in a StartCoroutine method. Otherwise, it won't execute properly, because it doesn't know how to handle the yield statements correctly. So- Should fix at least some of the problems. The confusion arises because in JS you don't need to explicity state that your function is a Coroutine- all that stuff gets magically inserted at compile time. Yikes, I just looked at the coroutine page on wikipedia. Is there a reference that might better explain what coroutines are? Your solution solves the problem, but now I'm curious.
Jan 23 '12 at 03:39 PM
cmauceri
This is what comes from borrowing code! :P
Jan 23 '12 at 03:40 PM
cmauceri
(comments are locked)
|

That line:
is that exactly how it is in your program? If so, I don't think it does what you expect. You are trying to call it as a member, not as a function. You should use
instead. Of course, if that was just pseudocode and not actually how it goes in your script, disregard this comment.
It wasn't supposed to be pseudocode, but I was a bit sloppy with copy and paste. Will edit.
The GUI code is not all the code I'm using, but if you think the problem might be hiding in another part of the code, I can post it complete.
Waait, is ScreenshotEncode meant to be a coroutine?