Skip to content
This repository was archived by the owner on Aug 16, 2024. It is now read-only.

Functions

JXSnack edited this page Apr 2, 2023 · 8 revisions

Creating a function

When you're in the script.json file, you can see a functions area. In that area you can write a function. In this example our function will be called "foo".

Example

"functions": {
	"add_to_foo": {
		"args": {},
		"execute": []
	}
},

Doing things in a function

Once you have your function, you probably want to do something with it. You can do everything that is doable. In our example we are going to add to a variable and then switch to a scene from the variable.

Example

{
	"global_variables": {
		"foo": 1
	},
	"functions": {
		"add_to_foo": {
			"args": {},
			"execute": [
				["add", "foo", 2],
				["scene", "foo"]
			]
		}
	},

Arguments in functions

Having arguments in functions is sometimes really needed. Imagine a lose function, but you can't set a reason why someone lost! That would be bad. That's why we added arguments! Arguments must always start with a capital letter and can't contain spaces. Calling an argument is simple! When in a string input, always use {arg:<YourArgNameHere>} and when in any other input just hope for the best and write the argument name.

Example

{
	"global_variables": {
		"foo": 1
	},
	"functions": {
		"add_to_foo": {
			"args": {"AddAmount": 1},
			"execute": [
				["add", "foo", "AddAmount"],
				["scene", "foo"]
			]
		}
	},

Changing the arguments is also really easy. Click on a button where you want to execute the function and click on Function arguments and then change the argument that you want to change.
change arguments change args

Executing functions

Executing functions is super easy. Just click on a button, then in Button action select Script, and then in Script function select the function that you want to execute. In our case it is add_to_foo.
select script and add to foo

You want to check if a variable has a specific value? Read checks

CrystalStudio

  • Settings
    • Custom theme (coming soon)
  • Project
    • Creating project (coming soon)
    • Open project (coming soon)
    • Bookmark project (coming soon)
  • Editor
    • Buttons (coming soon)
    • Scenes (coming soon)
    • Texts (coming soon)
    • Build/play Game (coming soon)

CrystalScript

Clone this wiki locally