Basic XQ Syntax

original guide by @z_u_ra on discord

This section of the guide assumes that you have basic programming knowledge with a language like Python or C-Sharp. If you don’t have any programming experience, I recommend this video.

Declaring Variables

in XQ, variables don’t have normal names like in other programming languages. to distinguish your variable from other variables, you need to call your variable $local and then a number. It’s good practice to always go up with the numbers. for example, if you see that the variable with the biggest number in the current function is $local10, don’t make something like $local88 because you feel quirky, do $local11. Not following this convention could lead to unexpected behavior. There are other types of variables other than local, I’ll go over them in a bit.

Declaring Functions

XQ function declarations are similar to languages like C# or C++, but XQ is dynamically written, so it’s a little bit different. for example, in C#, if I want to declare a function that returns a string, I would do

string foo() {
   return "bar";
}

but in XQ, functions can return any type and you don’t need to specify types, so it would look like this:

foo() {
  return "bar";
}

like other C-like languages, statements in XQ have to end with a semicolon. When declaring a function in XQ, parameters don’t have names, like local variables, they are simply called $param[number]. for example, this is how a function greeting the user would look like in C#:

string greet(string name) {
  string result = "Hello, " + name;
  return result;
}

in XQ, it would look like this:

greet($param0) {
  $local1 = format("Hello, %s!", $param0);
  return $local1;
}

Instructions

I would write a guide on this, but the creator of XtractQuery, onepiecefreak, has already done a fantastic job on that, so please read this to understand all the base instructions in XQ, This is super important.

Comments

You can define single line comments with // and multiline comments with /* comment */

Conditional Statements

In XQ, you can’t do do if blocks like in C# or Python, you need to use a conditional goto, furthermore, in XQ, bool literals are not allowed. so you have to prepare the conditional beforehand for example, if in Python it would be like this:

name = "john"
if name == "john":
  print("hey john")
else 
  exit(1)

in XQ it would look like this:

$local1 = "john";
$local2 = $local1 == "john";
if $local2 goto "johnYes"h;
return; // Essentially acts as an `else` statement because if the previous condition was true it would already jump to "johnYes".
"johnYes"h:
  $local1 = log("hey john");

So here’s an actually useful example you can copy and paste into your project. How would you do an action based on a flag’s value?

$object1_flagResult = get_global_bit_flag(flagId);
//Since flags can be either 1 or 0, you can directly check the value with an if statement
if $object1_flagResult goto "flagWorks"h;
//else go to after the check immediately
goto "afterCheck"h;

"flagWorks":
//Put the functionality for if the flag is 1 here

"afterCheck":

Hash Values

Unsigned integers or hex values have to end with h, as well as label literals. Hash values can also start with 0x and have hex codes instead of decimal values.

Stuff worth noting.

In XQs, even though some functions return void, every instruction has to be binded to a variable. You can’t just do PlayMovie(), you need to do $local1 = PlayMovie();, for example. This is only the tip of the iceberg; please visit the script specification on the XtractQuery github for more in-depth info about the syntax.

If you have any questions, please ping me, I am free almost all the time and I love answering questions.