String Arguments

Pazleysox

Member
I'm working on a script that uses
Code:
void main(string arguments)

First thing the script does (obviously) is ask player for input. Is there a way I can put the input back after displaying text?

Code:
void hello(string arguments)
{
[stuff to do with user input here]
}
void main()
{
print ("hello world");
hello(string arguments);
}
 
Last edited:

lostcalpolydude

Developer
Staff member
No, script inputs have to come before anything else the script does. There is a feature request asking to be able to prompt for inputs at an arbitrary time during script execution, but everyone with commit access was either uninterested or was against the idea of ever touching a script that tried making use of the feature.
 

Pazleysox

Member
Ok... It WAS a good idea. lol

Next question. I know how to get a list of the items I'm looking for in my inventory. Is there a way to have mafia spit out the item# along with it too?
 

Theraze

Active member
foreach it in get_inventory() {
if (it.to_int() == <somenumber>) {
do something with it
}
}
 

Pazleysox

Member
I seem to have found something on this topic. I did it completely by accident. Not sure if it's a bug or a feature, but this is great for a script I'm working on!

Code:
cli_execute("cls");
print("Welcome to my script");
print("Press A for a new message");
print("Press B for an old message");
print("Press C for instructions on killing the hermit");

void messageA()
{print("a new message");}
void messageB()
{print("an old message");}
void hermit()
{print("you can't");}

void main(string Letter)
{	effect requested_effect;
	letter = Letter.to_lower_case();

	if (letter.contains_text("a"))
	{	messageA();	}
	if (letter.contains_text("b"))
	{	messageB();	}	
        if (letter.contains_text("c"))
	{	Hermit();	}
}
Will output this:
letter.png
 

Bale

Minion
LoLoL!

In all the years I've seen people hammering at the issue of user input for scripts I don't think I've ever seen anyone come up with that solution before now.

It's definitely not an intended feature, but I understand why it works that way, so I don't think I can call it a bug either. Congratulations!
 

Pazleysox

Member
LoLoL!

In all the years I've seen people hammering at the issue of user input for scripts I don't think I've ever seen anyone come up with that solution before now.

It's definitely not an intended feature, but I understand why it works that way, so I don't think I can call it a bug either.
Congratulations![/QUOTE]

Thank you very much, this means a lot coming from someone who's scripts I use, and brain I've picked many times!

HAHAHA, funniest thing is I discovered it completely by accident too!

I put something at the top of my script, and forgot to code in a way to call it at the end, it was intended to restart the script, so I ended up in an endless loop. Once I figured out my mistake, I played with it a little bit, and came up with this! It was the solution to my problems! I figured I had to share it with the community too! :)
 

AlbinoRhino

Active member
Huh. I never realized this was not intended. A lot of my personal scripts are designed this way to remind me what input they take.
 

Bale

Minion
By "not intended," I didn't mean that mafia was behaving incorrectly. I only meant that this sort of interaction was not intended. (As I said, it is not a bug.)

Global scope is a powerful thing. I try not to put anything there other than global variables and sometimes the methods which assign their proper values. Which I why I'd not have thought to put print statements there. Also, when the input box has appeared it is impossible to check the CLI for instructions unless it is currently visible so that seems like an awkward thing to do. Interesting though.
 

Veracity

Developer
Staff member
I think it's because you can have a script that runs for a long time, and *then* asks for arguments for main()?
How could it operate any other way?

Top-level statements HAVE to be executed before main(), since they can initialize things that main() and functions it calls reference.
 

xKiv

Active member
How could it operate any other way?

Top-level statements HAVE to be executed before main(), since they can initialize things that main() and functions it calls reference.

They have to be executed before executing main, but not necessarilly before asking the user for arguments to main.
 
Top