Thread: [Tutorial] XSE Scripting Tutorial
View Single Post
Old 1st March 2018, 10:15 PM   #6
Avara
Mirage Of Tales Creator
 
Join Date: Nov 2013
Posts: 33
Avara
Default

Conditional Text Scripts

Let's start the next section with something nice and simple, shall we? Throwback to our msgbox command. This time we'll be looking at msgbox 0x5, or in other words, making a script where the player can answer "Yes" or "No".


Spoiler:
#dynamic 0x800000

#org @main
lock
faceplayer
msgbox @yesno 0x5
compare 0x800D 0x1
if 0x1 goto @YesOrg
msgbox @no 0x6
release
end

#org @YesOrg
msgbox @yes 0x6
release
end

#org @yesno
= Yes or no?

#org @yes
= You said yes.

#org @no
= You said no.

The goto command is exactly as it sounds; it literally tells the script to go to another pointer.
compare 0x800D, or compare LASTRESULT gets the result of the player's choice - in msgbox 0x5's case, 0x0 for 0 "No" or 0x1 for 1 "Yes".
Notice that when the player chooses "Yes", it doesn't go straight to the msgbox command which displays the text. This needs to be contained in its own script section, hence why I named the pointer "@YesOrg" for convenience. If you accidentally send your "Yes" pointer to the pointer for the text string(@yes) instead of the script section it's contained in (@YesOrg), bugs will follow.
If the LASTRESULT, or 0x800D is not 0x1 for "Yes" it will not goto @YesOrg, it just continues the script, meaning it displays the text string for @no and closes.

goto works just as well - the example below will give you the exact same results as the script above.


Spoiler:
#dynamic 0x800000

#org @main
lock
faceplayer
msgbox @yesno 0x5
compare 0x800D 0x1
if 0x1 goto @YesOrg
goto @NoOrg

#org @NoOrg
msgbox @no 0x6
release
end

#org @YesOrg
msgbox @yes 0x6
release
end

#org @yesno
= Yes or no?

#org @yes
= You said yes.

#org @no
= You said no.

-----------------------------------------------------------------------------------------------------------------------------------------------------

Let's go back to our basic NPC scripts for a moment. Every city needs filler NPCs, and they can get boring if they just say the same thing over and over again. In comes our next handy command, random. All it does is generate a random number within the range you set and then goes to the appropriate pointer, like this:

Quote:
Originally Posted by Avara View Post
random 0x[number of options you want]
compare 0x800D 0x0
if 0x1 goto @option1
[etc...]
Let's say you wanted a NPC to say three different things depending on the random number generated. You'd need a script like this:


Spoiler:
#dynamic 0x800000

#org @main
lock
faceplayer
random 0x03
compare 0x800D 0x0
if 0x1 goto @option1
compare 0x800D 0x1
if 0x1 goto @option2
compare 0x800D 0x2
if 0x1 goto @option3
end

#org @option1
msgbox @option1msg 0x6
release
end

#org @option2
msgbox @option2msg 0x6
release
end

#org @option3
msgbox @option3msg 0x6
release
end

#org @option1msg
= Message one text.

#org @option2msg
= Message two text.

#org @option3msg
= Message three text.

-----------------------------------------------------------------------------------------------------------------------------------------------------

Now we've covered random, we can move onto multichoice. For those of you who don't know what a multichoice box is, here's an example.


The layout for the multichoice command is as follows:

Quote:
Originally Posted by Avara View Post
preparemsg @pointer
waitmsg
multichoice 0x[X Co-ordinate of Box] 0x[Y Co-ordinate of Box] 0x[Multichoice ID]* 0x1

*Refer to multichoice IDs provided.
preparemsg prepares a text string to display and waitmsg is self explanitory, it just makes sure the full text is displayed before opening the multichoice box.
The 0x1 at the end means the player can't press B to exit the multichoice box. If it's 0x0 it can be cancelled with B - 0x1 is just my personal preference as it forces the player to pick a choice. Here's an example script from the above screenshot of a FireRed ROM, with "Yes", "No" and "Info" as options:

Spoiler:
preparemsg @pointer
waitmsg
multichoice 0xE 0x0 0x10 0x1
copyvar 0x8000 LASTRESULT
compare 0x8000 0x0
if 0x1 goto @yes
compare 0x8000 0x1
if 0x1 goto @no
compare 0x8000 0x2
if 0x1 goto @info
end

#org @yes
msgbox @yesmsg 0x6
release
end

#org @no
msgbox @nomsg 0x6
release
end

#org @info
msgbox @infomsg 0x6
release
end

The copyvar command here copies the result stored in LASTRESULT to var number 8000 so it can be compared to the result of the player's choice. More on vars later. Depending on the player's choice, you can make the script goto a different @pointer.

-----------------------------------------------------------------------------------------------------------------------------------------------------

Another minor conditional script example is one based on whether the player chose the male or female character - for this we could use the checkgender command:

Quote:
Originally Posted by Avara View Post
#org @start
lock
faceplayer
checkgender
compare LASTRESULT 0x0
if 0x1 goto @boy
goto @girl
If the value for the player's gender is 0, this means they are playing the male character and the script jumps to @boy, if not it goes to @girl. The value for the female character is 1, so vice-versa you can have this:

Quote:
Originally Posted by Avara View Post
#org @start
lock
faceplayer
checkgender
compare LASTRESULT 0x1
if 0x1 goto @girl
goto @boy
Ultimately, both of those examples do the same thing, so you can use either =)

Avara is offline   Reply With Quote
Likes Lunos liked this post