Skip to main content

GameClass

A script class that defines the game mode. Only one instance of this class is made.

This is the first script that will be run.

The game script is responsible for creating and managing Worlds.

The class can receive events sent with sm.event.sendToGame.

The fields below are accessed using self.fieldName in the GameClass script:

Fields:
TypeNameDescription
NetworknetworkA Network object that can be used to send data between client and server.
StoragestorageA server-side Storage object that can be used to save and load data to/from the world database.
anydataGame start data.
Constants:

defaultInventorySize
enableAggro
enableAmmoConsumption
enableFuelConsumption
enableLimitedInventory
enableRestrictions
enableUpgrade

Callbacks:

Server-only

onPlayerJoined

function GameClass.server_onPlayerJoined( self, player, newPlayer )
end

Called when a Player joins the game.

Arguments:
  • self [ table ]: The class instance.
  • player [ Player ]: The joining player.
  • newPlayer [ bool ]: True if the player has not been in this game before.

onPlayerLeft

function GameClass.server_onPlayerLeft( self, player )
end

Called when a Player leaves the game.

Arguments:
  • self [ table ]: The class instance.
  • player [ Player ]: The leaving player.

onReset

function GameClass.server_onReset( self )
end

Called when the user wants to reset the challenge level.

note

Only works in Challenge Mode!

Arguments:
  • self [ table ]: The class instance.

onRestart

function GameClass.server_onRestart( self )
end

Called when the user wants to restart the challenge level.

note

Only works in Challenge Mode!

Arguments:
  • self [ table ]: The class instance.

onSaveLevel

function GameClass.server_onSaveLevel( self )
end

Called when the user wants to save the challenge level.

note

Only works in the Challenge Builder!

Arguments:
  • self [ table ]: The class instance.

onTestLevel

function GameClass.server_onTestLevel( self )
end

Called when the user wants to save and test the challenge level.

note

Only works in the Challenge Builder!

Arguments:
  • self [ table ]: The class instance.

onStopTest

function GameClass.server_onStopTest( self )
end

Called when the user wants to stop testing the challenge level.

note

Only works in the Challenge Builder!

Arguments:
  • self [ table ]: The class instance.

Client-only

onLoadingScreenLifted

function GameClass.client_onLoadingScreenLifted( self )
end

Called when the loading screen is lifted when entering a game.

Arguments:
  • self [ table ]: The class instance.

onLanguageChange

function GameClass.client_onLanguageChange( self, language )
end

Called when the user changes the language in the in-game menu.

Valid languages are: Brazilian, Chinese, English, French
German, Italian, Japanese, Korean
Polish, Russian, Spanish

Arguments:
  • self [ table ]: The class instance.
  • language [ string ]: The new language.