January 2016
Beginner
512 pages
12h 35m
English
The first task is to read the script, extract the needed functions from it, and store them in a safe place. Then, load the project for the game and add a new class with the following code:
class AIScript {
public:
QScriptProgram read(const QString &fileName);
bool evaluate(const QScriptProgram &program, QScriptEngine *engine);
QScriptValue initFunction;
QScriptValue heartbeatFunction;
QScriptValue defendFunction;
};The reading method can have the same content as the original readScriptFromFile method. The evaluate method looks as follows:
bool AIScript::evaluate(const QScriptProgram &program, QScriptEngine *engine) { QScriptContext *context = engine->pushContext(); QScriptValue activationObject; QScriptValue ...