ash

package
v0.0.0-...-0cacbfc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 8, 2024 License: GPL-2.0 Imports: 6 Imported by: 6

README

Introduction

Ash is a scripting language that executes Burn commands in a conditional loop.

This allows creating cutscenes and special events using the game world objects.

Examples

Infinite loop script:

# Every 5 seconds, sends text from first argument on chat
# channel of object with serial ID from second argument
true {
    objectset -o chat -a @1 -t @2;
    wait(5);
};

Script with inner block:

# Script that sets position of character with serial ID from arg 1
# to 0x0 if range between him and character with serial ID from arg 2
# is less than 50.
true {
    rawdis(@1, @2) < 50 {
      objectset -o position -a 0 0 -t @1;
      wait(5);
    };
};

Declaring arguments inside script:

# Script that sets position of character with serial ID from arg 1
# to 0x0 if range between him and character with serial ID from arg 2
# is less than 50.
@1 = char#1
@2 = char#3
true {
    rawdis(@1, @2) < 50 {
      objectset -o position -a 0x0 -t @1;
      wait(5);
    };
};

For loop:

# Script that sends arg2 text on chat channel of character with
# arg 1 serial ID if raw distance between him and any character from
# area with ID 'area1_main' is less than 50, after that script halts 
# for 5 secs.
@1 = testchar#0
@2 = "hay you!"
true {
	for(@3 = out(moduleshow -o area-chars -t area1_main)) {
     		rawdis(@1, @3) < 50 {
        		objectset -o char -a @2 -t @1;
        		wait(5);
	     	};
	};
};

Output comparison:

# Script that sends arg2 text on chat channel of character with
# arg1 serial ID if raw distance between him and any character from
# area with ID 'area1_main'(expect char with arg1 serial ID) is less 
# than 50, after that script halts for 5 secs.
@1 = testchar#0
@2 = "hay you!"
true {
	for(@3 = out(moduleshow -o area-chars -t area1_main)) {
		@1 != @3 {
	     		rawdis(@1, @3) < 50 {
				objectset -o chat -a @2 -t @1;
				wait(5);
		     	};
		};
	};
};

End macro:

# Spawns character with arg1 ID in area with arg2 ID 
# then ends script.
@1 = testchar
@2 = area
{
	moduleadd -o char -a @1 @2;
	end();
}

Documentation

Index

Constants

View Source
const (
	CommentPrefix = "#"
	BodyExprSep   = ";"
	VarPrefix     = "@"
	// Keywords.
	TrueKeyword   = "true"
	EchoKeyword   = "echo"
	WaitKeyword   = "wait"
	RawdisKeyword = "rawdis"
	OutKeyword    = "out"
	EndKeyword    = "end"
)

Variables

This section is empty.

Functions

func Run

func Run(scr *Script) error

Run runs specified script.

Types

type BlockType

type BlockType int

Type for block type.

const (
	CaseBlock BlockType = iota
	ForBlock
)

type ComparisonType

type ComparisonType int

Type for script case types.

const (
	Greater ComparisonType = iota
	Equal
	Less
	Dif
	For
	True
)

type ExpressionType

type ExpressionType int
const (
	Expr ExpressionType = iota
	EchoMacro
	WaitMacro
	EndMacro
)

type Script

type Script struct {
	// contains filtered or unexported fields
}

Struct for Ash script.

func NewScript

func NewScript(name, text string, args ...string) (*Script, error)

NewScript creates new Ash script from specified text, returns error in case of syntax error.

func (*Script) Blocks

func (s *Script) Blocks() []*ScriptBlock

Blocks returns script blocks with expressions.

func (*Script) Name

func (s *Script) Name() string

Name returns script name.

func (*Script) Stop

func (s *Script) Stop(stop bool)

Stop toggles script stop flag.

func (*Script) Stopped

func (s *Script) Stopped() bool

Stopped checks if script was stopped.

func (*Script) String

func (s *Script) String() string

String returns script text body.

type ScriptBlock

type ScriptBlock struct {
	// contains filtered or unexported fields
}

Struct for script expression block.

func (*ScriptBlock) Blocks

func (b *ScriptBlock) Blocks() []*ScriptBlock

Blocks returns all inner blocks.

func (*ScriptBlock) Condition

func (b *ScriptBlock) Condition() *ScriptCase

Conditon returns block condition case.

func (*ScriptBlock) ExecuteCounter

func (b *ScriptBlock) ExecuteCounter() int

ExecuteCounter returns block execute counter.

func (*ScriptBlock) Expressions

func (b *ScriptBlock) Expressions() []*ScriptExpression

Expressions returns all expression within block.

func (*ScriptBlock) SetExecuteCounter

func (b *ScriptBlock) SetExecuteCounter(i int)

SetExecuteCounter sets specified number as value of block execute counter.

func (*ScriptBlock) SetVariable

func (b *ScriptBlock) SetVariable(n, v string) *ScriptBlock

SetVariable sets variable with specified name and value for block expressions.

func (*ScriptBlock) Stop

func (b *ScriptBlock) Stop(stop bool)

Stop toggles block stop flag.

func (*ScriptBlock) Stopped

func (b *ScriptBlock) Stopped() bool

Stopped checks if block was stopped.

func (*ScriptBlock) String

func (b *ScriptBlock) String() string

String returns block text.

type ScriptCase

type ScriptCase struct {
	// contains filtered or unexported fields
}

Struct for script case.

func (*ScriptCase) CorrectRes

func (c *ScriptCase) CorrectRes(r string) (bool, error)

CorrectRes checks if specified result value is correct.

func (*ScriptCase) Expression

func (c *ScriptCase) Expression() burn.Expression

Expression returns case expression.

func (*ScriptCase) String

func (c *ScriptCase) String() string

String returns condition text.

type ScriptExpression

type ScriptExpression struct {
	// contains filtered or unexported fields
}

Struct for script expressions.

func NewEchoMacro

func NewEchoMacro(text string, expr burn.Expression) *ScriptExpression

NewEchoMacro returns new script expression for echo macro.

func NewEndMacro

func NewEndMacro() *ScriptExpression

NewEndMacro returns new script expression for end macro.

func NewExpression

func NewExpression(expr burn.Expression) *ScriptExpression

NewExpression returns new script expression for specified burn expression.

func NewWaitMacro

func NewWaitMacro(millis int64) *ScriptExpression

NewWaitMacro returns new script expression for wait macro.

func (*ScriptExpression) BurnExpr

func (se *ScriptExpression) BurnExpr() burn.Expression

BurnExpr returns burn expression or empty struct if there is no burn expression in this script expression.

func (*ScriptExpression) Type

func (se *ScriptExpression) Type() ExpressionType

Type returns expression type.

func (*ScriptExpression) WaitTime

func (se *ScriptExpression) WaitTime() int64

WaitMillis returns number of milliseconds to wait before expression execution.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL