[Solved] Multiple functions in one string

Hello every one, i don’t have any issue everything worked as it should but i wanted to spice up a little bit this game to look more like some one was presenting the number wizard and change things a little bit when i was writing i stumble upon this problem i wish i could make the code below using the + min + max in only one string

print (“Welcome to number Wizard”);
print (“Be prepared, to the wonders that wizard will show you”);

int max = 1000;
int min = 1;

print ("pick a random number to your head, you can choose any given number from: ");
print ( + min);
print ("to");
print ( + max);
print ("and the wizard with his vast knowledg will ask you some questions and tell you exactly the number you, thougt");

To something that could fit into one string i thought it should be something like this

print ("pick a random number to your head, you can choose any given number between ") (+ min " to " + max);

but it didn’t work.

Can some one help me ?

1 Like

Hello @Fernando_Fernandes,

You need to concatenate the strings within the brackets for the print statement.

Example;

print ("Hello " + "Fernando " + "Fernandes");

It’s the same if you use variables also;

string greeting = "Hello";
string name = "Fernando Fernandes";

print (greeting + " " + name);

Hope this helps :slight_smile:


See also;

2 Likes

Hello bob, i’m very pleased to know that there are people active to help thanks for taking your time and help me, but see, if i do this like this, the way that i’ve understand your explanation to the print command

    int max = 1000;
int min = 1;

print ("pick a random number to your head, you can choose any given number from: " + min " to " + max );

i get the following error

i’ve already tried this in the unity 4.6.9 and the one i’m using right now that is the 5.5.2f1

the string procedure that you showed me may work but counting all the the time i’ve watched the course it shouldn’t be more then 2 hours so i’m a little afraid to get a little confused and overwhelmed so i’m trying with the tools the course has showed me till now, i’m starting to believe that is not possible to use the INT function twice in the same string is that correct or am i forgetting a bracket or a inverted commas or anything like that ?

1 Like

Hello @Fernando_Fernandes,

You need to ensure that you place a + sign to concatentate each item…

If you look at your code above you will note that there is a missing + character missing from in front of the " to "

See below;

int max = 1000;
int min = 1;
print ("pick a random number to your head, you can choose any given number from: " + min + " to " + max );

Hope this helps

1 Like

Ohhhhhhhh thanks @Rob it really helped, it worked just fine, i have just one more question so i can understand a little more if i need to put more than 2 i’ll always add the + in the end so i can concatentate every one together right ? the semi colon was ok i just coppy it wrong XD

thanks once more for your help.

1 Like

You’re more than welcome, and yes, each time you need to add a part to the total string you will need to provide a + character before it…

So, for example;

print("my " + "really" + "long " + "concatenated " + "string " + " of " + " words ");

It can obviously get a little bit messy though, and you may consider writing a custom method instead which takes care of adding all the parts together and managing the spaces and tidying up any trailing spaces etc.

I would use this sparingly though, just where you really need it.

1 Like

Yea i thought that there is more easy and pratical methods to do this is just that i’m really new to programming never saw anything before but sure once i get the hang of things i’ll use this method less times.

Thanks man.

You’re more than welcome. :slight_smile:

1 Like