Categories
Coding

XtScript: Include

Having a long XtScript codes in one block could be confusing and hard to manage especially on mobile device with small screen. That’s when the include command come in handy.

We can load external XtScript file and use on our codes using include command. XtScript file has .xt extension.

After we have included an XtScript file, the command and script written in the file will be executed and run normally.

We also can access the variable declared in the included XtScript file by adding @ prefix to the variable name (e.g. @$variable).

Learn XtScript Include from example

Include an XtScript file named “xtscript-include.xt” at /demo/ directory on this site.

<!--parser:xtscript-->
  # Include an XtScript file. The path is relative to this site directory
  include /demo/xtscript-include.xt
  # Use "@" prefix to access the variable in the included XtScript file
  print <p><b>I am playing games using my @$device</b></p>
<!--/parser:xtscript-->

This is some parapraph from $text variable written in a file named “xtscript-include.xt” that located at /demo/ directory on the xtgem site.

I am playing games using my Tablet

Here is what is written inside the included XtScript file:

var $text = <p>This is some parapraph from \$text variable written in a file named "xtscript-include.xt" that located at <i>/demo/</i> directory on the xtgem site.</p>
var $device = Tablet
print $text

Just like Javascript and PHP, the included external XtScript file also must be written without the opening and closing tag (<!--parser:xtscript--> <!--/parser:xtscript-->).

By SiDar

Webmaster Assistant and Editor at Indotechboy.com.

SiDar enjoying himself listening J-pop genre music and playing games, especially old school games. Sometimes he also found watching anime and reading manga are interesting when his fellow author recommend him some good titles.

Leave a Reply

Your email address will not be published. Required fields are marked *