Hello world
A script contains one or more rooms. A Start[] function runs automatically unless it has [DR].
zsharp = type.script
noticed room Test[] (
noticed text HelloWorld = "Hello World":
noticed brain Start[] (
Print(HelloWorld):
)
)
Words with a job
Z# uses descriptive keywords while keeping familiar behavior from C#, Java, and C.
noticedpublicVisible from anywhere allowed by imports
silentprivateLimited to its containing or parent room
roomclassGroups variables and functions
brainvoidA function with no fixed return type
numbernumberA signed whole or decimal value
textstringText inside double quotes
statusbooleanalive or dead
hordestaticBelongs to the room rather than an object
feedreturnEnds a function and optionally supplies a value
noticed number Score = 10:
noticed text Name = "Zombie":
noticed status Alive = alive:
noticed text() Names = ["Alex", "Sam", "Robin"]:
number.set:Score = Score + 5:
text.set.Name = Name + "!":
Functions and calls
Use feed for a returned value. Fully qualified calls follow Project:File:Room:Function, with unneeded location parts left out.
noticed number Add[number Left, number Right] (
feed(number.Left + number.Right):
)
noticed brain Start[] (
number Result = Function.call(Math:Calculator:Add [4, 6]):
Print(Result):
)
Conditions and loops
Conditions support and and or. A loop continues until loop.end:; continue: starts its next pass. wait and delay accept milliseconds or seconds.
if[Alive and Health > 0] (
Print("Still going"):
) else (
Print("Game over"):
)
loop (
wait(1s):
if[Health == 0] (loop.end:)
)
Imports and access
Imports live inside a room and expose an entire file. Wildcards work at any import level. Code in another project, file, or room follows the same outside-to-inside order.
import Project.Folder.File():
import ZSharp.Window.*():
import another_project.*():
Print(Room.Score):
Print(File.Room.Score):
Print(Project.File.Room.Score):
Objects and arrays
Array types add () after the value type. Objects are created with new, and their fields and functions use dot access.
noticed text() Names = ["Alex", "Sam", "Robin"]:
Print(Names[1]):
noticed Player User = new Player["Zombie"]:
User.Move[10, 20]:
Print(User.Name):
User.Move in the same room, Room.User.Move from another room, then add the file and project names only when crossing those boundaries.Native windows
A window file contains one window. Measurements without a suffix use zu, which follows display scale; use px for literal pixels. Positive X moves right and positive Y moves up.
zsharp = type.script:window
noticed Window Startup[] (
import ZSharp.Window.*():
noticed design Design[] (
title: "My Z# App":
icon: "assets/images/icon.png":
scalable: alive:
background: linear-gradient(90:#E52C3A:#5D0C38):
)
noticed button Launch[] (
text: "Launch":
width: 34zu:
height: 12zu:
Click[left: [Scripts:Actions:Launch]: right: []:]:
)
)
Live UI changes
Scripts can change window properties while an app is running. Gradients accept any number of colors, and wait or delay can pace an animation.
Startup.Design.background.set: linear-gradient(90:#FF0000:#00FF00:#0000FF):
wait(1s):
Startup.Design.background.set: radial-gradient(180:#121212:#73001F):
Startup.AppTitle.content.set: "Ready":
Start[] functions from running.Project settings
Every project is described by project.zsettings. It sets the project identity and version, selects the Z# release, declares dependencies, and chooses the startup window for an app.
zsharp = type.settings
Project: "My Z# App":
PID: "my_zsharp_app":
Version: [1.0.0.0]:
Authors: ["Your Name"]:
Description: "Built with Z#":
ZSharp: []:
Dependencies (
zsharpwindow:1.0.0.0
):
Window (
Startup: "Windows/Startup.zsharp":
Uninstall: "Windows/Uninstall.zsharp":
):
Build an app
Register the project, package it, and run the resulting .zapp. Packages are created inside the project's Packages folder.
zsharp project "path/to/project.zsettings"
zsharp package app "path/to/project" MyApp
zsharp run "path/to/project/Packages/MyApp.zapp"
--unbytecode to create both the normal bytecoded app and an unbytecoded package containing the original source.Compiler feedback
The compiler reports misspelled keywords, missing statement terminators, unclosed rooms or functions, invalid values, and references that were not imported. Messages include the source file and line so the problem can be fixed before packaging.
Scripts/Player.zsharp:14:3: expected ':' after the statement
Windows/Startup.zsharp:8:2: File.Room was used without an import