Adding WA.onInit method to wait for API startup.
This commit is contained in:
parent
62a4814961
commit
abd53b6251
9 changed files with 71 additions and 383 deletions
30
docs/maps/api-start.md
Normal file
30
docs/maps/api-start.md
Normal file
|
@ -0,0 +1,30 @@
|
|||
{.section-title.accent.text-primary}
|
||||
# API start functions Reference
|
||||
|
||||
### Waiting for WorkAdventure API to be available
|
||||
|
||||
When your script / iFrame loads WorkAdventure, it takes a few milliseconds for your script / iFrame to exchange
|
||||
data with WorkAdventure. You should wait for the WorkAdventure API to be fully ready using the `WA.onInit()` method.
|
||||
|
||||
```
|
||||
WA.onInit(): Promise<void>
|
||||
```
|
||||
|
||||
Some properties (like the current user name, or the room ID) are not available until `WA.onInit` has completed.
|
||||
|
||||
Example:
|
||||
|
||||
```typescript
|
||||
WA.onInit().then(() => {
|
||||
console.log('Current player name: ', WA.player.name);
|
||||
});
|
||||
```
|
||||
|
||||
Or the same code, using await/async:
|
||||
|
||||
```typescript
|
||||
(async () => {
|
||||
await WA.onInit();
|
||||
console.log('Current player name: ', WA.player.name);
|
||||
})();
|
||||
```
|
Loading…
Add table
Add a link
Reference in a new issue