Script Cookbook - theRAPTLab/gsgo GitHub Wiki
This is a collection of short "recipes" that demonstrate how to use the different GEMSCRIPT concepts. Use this as a quick reference guide. See Script Reference Index for full reference.
Table of Contents
[[TOC]]
-
.json
files are TexturePacker spritesheets that contain more than one image. By default, frame 0 of the spritesheet will be displayed. You can set the frame usingagent.Costume.currentFrame
property -
.png
are simple single images.addFeature Costume featProp agent.Costume.costumeName setTo `square.json` // DEPRECATED // featCall agent.Costume setCostume 'square.json' <frame>
Colorizes a character by overlaying the color on top of the base sprite color. When using the Wizard, the color can be selected via a popup color picker.
addFeature Costume
featProp character.Costume.color setToColor 16711680
Where color is a decimal number corresponding to the hex RGB color. e.g. #FF0000
is 16711680
Sets absolute size of agent in pixels (world units). Sets the largest side of the sprite to the to retain the aspect ratio. By default, costumes will appear at full size. e.g. a png that is 900 x 400 will be huge when added.
featProp agent.Costume.size setTo 10
// DEPRECATED
// addFeature Physics
// featCall agent.Physics setSize <width-in-pixels> <height-in-pixels>
Sets absolute width or height of agent in pixels. This will override the size
setting. Use this to deform the image.
featProp agent.Costume.width setTo 10
featProp agent.Costume.height setTo 20
Sets size of agent relative to base costume as a ratio, where 1 = 100%, 0.5 = 50%, 1.5 = 150%, etc. By default scale is 1 (100%). The scaling is applied on top of the size
or width/height
the costume has been set to. For example, if size=10
, and scale=2
, then costume will be set to 10 x 2 = 20 pixels
featProp agent.Costume.scale setTo 2
// Optionally, set a different Y scale (make it tall!)
featProp agent.Costume.scaleY setTo 4
// DEPRECATED
// addFeature Physics
// featProp agent.Physics scale <ratio>
Sets how characters move about. See also Movement
// wander around
addFeature Movement
featProp agent.Movement.movementType setTo wander
// to set wander "speed" (default is 0.5)
// 0.25 -- snail's pace
// 1 -- leisurely
// 4 -- medium
// 8 -- quick
// 20 -- fast (more than 20 is hitchy)
featProp agent.Movement.distance setTo 5
// stop moving
addFeature Movement
featProp agent.Movement.movementType setTo stop
// place agent at specific spot -- <x> and <y> are world units (pixels)
addFeature Movement
featProp agent.Movement.targetX setTo 100
featProp agent.Movement.targetY setTo 100
featProp agent.Movement.movementType setTo setLocation
// or //
featCall agent.Movement queuePosition <x> <y>
// move to a specific spot
addFeature Movement
featProp agent.Movement targetX setTo <x>
featProp agent.Movement targetY setTo <y>
featProp agent.Movement.movementType setTo goLocation
// to set how quickly character moves to location (default is 0.5)
featProp agent.Movement.distance setTo 5
// wiggle around
addFeature Movement
featProp agent.Movement.movementType setTo jitter
// to set how much far to wiggle (default is 5)
featProp agent.Movement.jitterDistance setTo 10
On the source (Moth) agent:
# BLUEPRINT Moth
addFeature Physics
addFeature Costume
addFeature Touches
featCall Moth.Touches monitor Tree b2b
when Moth touches Tree [[
featCall Moth.Costume setGlow 0.5
]]
On the target (Tree) agent: IMPORTANT: Touches won't work if the target does not have Physics enabled
# BLUEPRINT Tree
addFeature Physics
addFeature Costume
Set custom text label:
# BLUEPRINT Moth
addFeature AgentWidgets
featProp Moth.AgentWidgets.text setTo 'Player Moth'
Bind text label to an agent property:
# BLUEPRINT Moth
addFeature AgentWidgets
addProp energyLevel number 0
featProp Moth.AgentWidgets.textProp setTo energyLevel
Set meter value:
# BLUEPRINT Moth
addFeature AgentWidgets
featProp Moth.AgentWidgets.meter setTo 50
Bind meter value to an agent property
# BLUEPRINT Moth
addFeature AgentWidgets
addProp energyLevel number 0
featProp Moth.AgentWidgets.meterProp setTo energyLevel