Skip to content

scripts_system::script

Paweł Waligóra edited this page May 9, 2024 · 17 revisions

Full signature: class scripts_system::script

namespace scripts_system {
	class script {
	public:
		std::string name;

		script() : name("") {};
		script(const std::string& name_) : name(name_) {};

		virtual void start() {};
		virtual void update() {};

		virtual ~script() {};
	};
}

Class is meant to be abstract. Should be overridden. Place your custom classes that inherit from scripts_system::script in namespace game

  • methods
    • scripts_system::script::start() - called once just before first update
    • scripts_system::script::update() - called every iteration of game loop

All methods are called by scripts_system::call_events(), after object has been registered with: scripts_system::subscribe(&object) - preferred.

Methods can be registered individually with: scripts_system::subscribe(std::bind(&game::your_script::method, &object), SCRIPTS_TYPE), where SCRIPTS_TYPE can be one of the following:

  • SCRIPTS_START
  • SCRIPTS_UPDATE

Usage Example

my_script.h

#pragma once
#include "scripts_system.h"

namespace game {
	class my_script : public scripts_system::script {
	public:
		virtual void start();
		virtual void update();

		// other public members

	private:
		// private members
	};
}

my_script.cpp

#include "my_script.h"

void game::my_script::start() {
	// this code will execute once just before game loop
}

void game::my_script::update() {
	// this code will execute once every program step
}

// other members definitions

Home

Git Workflow

Issues

Coding Rules

Skrypty-Tutorial

Useful resources

Game Structure

Code Structure

Clone this wiki locally