How would I rerun a script?

lightwriter
How would I loop a script?
What I mean is something like this:
Enter Name:
>Tyller
Is this correct? (Yes, No)
>No
Enter Name:
>Tyler
I looked over the functions and scripts and couldn't find something to do this...
The solution for this case was I just had the player re-enter the setup room and so it ran the room's script again but I'm wondering if there's a simpler solution that doesn't involve moving the player back and forth using a dummy room.

jaynabonne
Put your script inside a function, and then have the script call the function itself again if it's not a correct answer. (It's not recursion as such since "get input" doesn't block. It just kicks off another input session.)

HegemonKhan
there's three ways to do so:

1. Functions
2. Scripts (Script Attributes)
3. Delegates (Scripts with the same powers as Functions have: able to return Values+Parameters)

examples:

1. Functions:

to activate~execute~run~call~do~use (which includes again, aka: re-running it) a Function, it is literally the Function's Name as the command to do so.

in code: Function_name

in GUI~Editor: run as script -> add a~new script -> 'whatever the category' -> 'call function' Script -> (see below)

Name text box: (type in the Name of the Function that you want to do~use)
Parameters (add a parameter) box: (optional, a bit confusing~advanced for new people to get, but it's really actually very simple once you get the concept of them)
Return Type drop down box: (optional, a bit confusing~advanced for new people to get, but it's really actually very simple once you get the concept of them)

<asl version="560">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="testing game stuff">
<gameid>b073bbfb-0e99-45d3-9786-bb395a6bc6b0</gameid>
<version>1.0</version>
<firstpublished>2015</firstpublished>
<pov type="object">player</pov>
<start type="script">
first_name_string_function (game.pov)
<start>
</game>
<object name="room">
<inherit name="editor_room" />
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
</object>
</object>
<object name="global_data_object">
<inherit name="editor_object" />
<attr name="yes_or_no_stringlist_attribute" type="simplestringlist">yes;no</attr>
</object>
<function name="first_name_string_function" parameters="player_parameter">
msg ("What is your name?")
get input {
temporary_first_name_string_variable = ToString (result)
show menu ("Is this (" + temporary_first_name_string_variable + ") your first name?", global_data_object.yes_or_no_stringlist_attribute, false) {
if (result = "yes") {
player_parameter.first_name_string_attribute = temporary_first_name_string_variable
msg ("Your first name is: " + player_parameter.first_name_string_attribute + ".")
wait {
ClearScreen
}
} else if (result = "no") {
ClearScreen
first_name_string_function (player_parameter)
}
}
}
</function>
</asl>


2. Scripts

<asl version="560">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="testing game stuff">
<gameid>b073bbfb-0e99-45d3-9786-bb395a6bc6b0</gameid>
<version>1.0</version>
<firstpublished>2015</firstpublished>
<pov type="object">player</pov>
<start type="script">
invoke (global_data_object.first_name_string_script_attribute)
<start>
</game>
<object name="room">
<inherit name="editor_room" />
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
</object>
</object>
<object name="global_data_object">
<inherit name="editor_object" />
<attr name="yes_or_no_stringlist_attribute" type="simplestringlist">yes;no</attr>
<first_name_string_script_attribute type="script">
msg ("What is your name?")
get input {
temporary_first_name_string_variable = ToString (result)
show menu ("Is this (" + temporary_first_name_string_variable + ") your first name?", global_data_object.yes_or_no_stringlist_attribute, false) {
if (result = "yes") {
game.pov.first_name_string_attribute = temporary_first_name_string_variable
msg ("Your first name is: " + game.pov.first_name_string_attribute + ".")
wait {
ClearScreen
}
} else if (result = "no") {
ClearScreen
invoke (global_data_object.first_name_string_script_attribute)
}
}
}
</first_name_string_script_attribute>
</object>
</asl>


3. Delegates (I'm still learning these myself... and too lazy~tired to try to write out this example), so here is the link on them:

http://docs.textadventures.co.uk/quest/ ... gates.html

----------

About Parameters:

they let you you transfer~use (and also, optionally to temporarily re-label~name them too) Attributes across Functions, Delegates, Commands, and etc.

so in my (1.) Function example test game code above:

coceptually: game.pov <=== player // if you don't know about 'game.pov' yet, just understand that the 'game.pov' is the same as 'player' for this example.

we activate the 'first_name_string_function' Function in the 'game' Game Object's 'start' Script, and we want to get and use the 'game.pov' Attribute in the Function, which we do via:

first_name_string_function (game.pov)

now, within the Function, I like to change it's name, just to avoid any possible conflicts with the Attribute and to describe what I'm doing with what for myself when I look at my code later on, which is done via this:

<function name="first_name_string_function" parameters="player_parameter">

conceptually: player_parameter <=== game.pov <=== player

----------

ask if you got any questions, also, you can take a look at this link too:

viewtopic.php?f=18&t=4988

to see my own system so far for character creation (I don't like using the popup menus of the 'show menu' Script), for some ideas for you.

jaynabonne
Delegates would be way overkill for this. The advantage of delegates is either 1) taking in parameters, or 2) getting a return value, neither of which is needed for this simple case.

This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums