Skip to content

Instantly share code, notes, and snippets.

@thelink2012
Last active November 13, 2016 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thelink2012/81c33abe485140dc95f39b8e7c29157a to your computer and use it in GitHub Desktop.
Save thelink2012/81c33abe485140dc95f39b8e7c29157a to your computer and use it in GitHub Desktop.
  • Feature Name: gta3sc-define
  • Start Date: 11/11/2016

Summary

Means of defining string constants within GTA3script files.

Motivation

String constants are most of the time important for readability, and there's no known way to define them within the compilation stage.

Suspicious commands exist (CONST_INT / CONST_FLOAT / CONSTANT_INT), but it's not feasible to infer their semantics purely by the command name.

Detailed design

ID Command Name Command Hash Params
None DEFINE_INT 0x4ce823af IDENTIFIER INT
None DEFINE_FLOAT 0x2786fb5a IDENTIFIER FLOAT

The first parameter for the commands is the string constant the value will assume, and the second is the value in question.

Those constants should behave like the constants TRUE/FALSE. That is, they can be used mostly anywhere and shouldn't use the CONSTANT variants of the set and comparision operations.

Constants defined by those command are propagated between script files, as seen in the example below.

Example

main.sc:

DEFINE_INT LOW_HEALTH 100

VAR_INT car
VAR_FLOAT f

f = FLOAT_ONE + 10.0
CREATE_CAR 0 f FLOAT_ONE 0.0 car

SET_CAR_HEALTH car LOW_HEALTH
SET_CAR_HEALTH car FULL_HEALTH

GOSUB_FILE dummysub file.sc
TERMINATE_THIS_SCRIPT

main/file.sc

DEFINE_INT FULL_HEALTH 1000
DEFINE_FLOAT FLOAT_ONE 1.0

dummysub:
RETURN

Drawbacks

Why should we not do this?

Alternatives

Any other alternative?

Unresolved questions

Anything to still be discussed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment