|
107 | 107 | print(f.text)<br /> |
108 | 108 | }<br /> |
109 | 109 | read_local_file(get) // establish callback </p> |
110 | | - <p class="Normal">The function <span class="attribute">get_library()</span> times out if the library cannot be loaded and posts an alert to the user, asking whether the user wants to attempt the operation again. Here is a way to use this function without the keyword <span class="attribute">wait</span>:</p> |
| 110 | + <p class="Normal">The function <span class="attribute">get_library()</span> times out if the library cannot be loaded and posts an alert to the user, asking whether the user wants to attempt the operation again. Here is one way to use this function: </p> |
111 | 111 | <p class="program">var loaded = false<br /> |
112 | | - var start = new Date().getSeconds()<br /> |
113 | | - var load = function() { loaded = true }<br /> |
| 112 | + var load = function() { loaded = true }<br /> |
114 | 113 | <br /> |
115 | 114 | get_library(file, load)<br /> |
116 | 115 | <br /> |
117 | 116 | var wait_for_load = function() {<br /> |
118 | 117 | if (loaded) {<br /> |
119 | 118 | print('Got library')<br /> |
| 119 | + // use the library <br /> |
120 | 120 | } else {<br /> |
121 | | - var t = new Date().getSeconds()<br /> |
122 | | - if (t - start > 2) {<br /> |
123 | | - print("Takes more than 2 sec")<br /> |
124 | | - } else {<br /> |
125 | | - rate(30,wait_for_load)<br /> |
| 121 | + rate(30,wait_for_load)<br /> |
126 | 122 | }<br /> |
127 | 123 | }<br /> |
128 | 124 | <br /> |
129 | | - wait_for_load()</p> |
| 125 | + wait_for_load()<br /> |
| 126 | + while (!loaded) {<br /> |
| 127 | + rate(30,wait)<br /> |
| 128 | +}<br /> |
| 129 | +print('Library is loaded') |
| 130 | +<br /> |
| 131 | + </p> |
130 | 132 | <p class="Normal">The same structure can be used with <span class="attribute">scene.waitfor('textures',load)</span>, with the difference that there is no timeout; if any of the textures requested for objects cannot be found, the load() function will never be called. This structure can also be used with <span class="attribute">scene.pause('Click to see something',load)</span>.</p> |
131 | 133 | <p class="Normal"> </p> |
132 | 134 | <!-- InstanceEndEditable --></td> |
|
0 commit comments