Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Return Object page #495

Merged
merged 8 commits into from
Dec 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions docs/scripting/syntax/return_object.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
title: Return Object
alias:
- success object
- failure object
---

An object returned to the CLI from a script may be automatically formatted, depending on its contents. These types of objects are often referred to as ((%LSuccess%)) or ((%DFailure%)) objects.

## Syntax

A ((%LSuccess%)) or ((%DFailure%)) object can only contain two keys. The `ok` key is required, and determines whether ((%LSuccess%)) or ((%DFailure%)) is displayed in the terminal. You may also attach a `msg` key, which will append that value, after being converted to a string.

## Example

```js
function(context, args) {
//Explains the guessing game when the script is run without a guess.
if (!args.guess) {
return "Let's play a guessing game! Guess a number between 1 and 10!"
}

//Return a success object if they guess they right number.
if (args.guess == Math.floor(Math.random() * 10)) {
return {
ok: true,
msg: args.guess + " was the right number!"
}
}

//In all other cases, return a failure object.
return {
ok: false,
msg: "Sorry, please guess again!"
}
}
```

## See Also

- [[ok]]
- [[not_impl]]
Loading