Jump to content


Photo

Adding an indefinite amount of strings


  • Please log in to reply
4 replies to this topic

#1 Andyh444

Andyh444

    GMC Member

  • GMC Member
  • 60 posts

Posted 19 September 2010 - 02:24 PM

Ok, well I guess my question makes the most sense if put in context, so...
I'm making an RPG, and in this RPG there are various crimes you can commit to put a bounty on your head. The more crimes you commit, the higher your bounty. If the guards catch you, you have the choice of paying off your bounty with your money, or serving a jail sentence. Just like in Oblivion.

The penalty for serving a jail sentence is that your skills decrease, and the amount of skills that decrease depends on your bounty. I want to be able to summarise the amount of skills that decrease in a single string.

My code is like this:

times_to_repeat=floor(bounty/100)
number_of_strings=0

repeat(times_to_repeat)
{
aa=ceil(random(2))
if aa=1
{
number_of_strings+=1
msg_string[number_of_strings]='Skill1 has decreased by 1'
skill1-=1
}

if aa=2
{
number_of_strings+=1
msg_string[number_of_strings]='Skill2 has decreased by 1'
skill2-=1
}
}

I have more than 2 skills, and they're obviously not called skill1, skill2, etc...
I just used that as an example.

And the message code I currently use is this:
if number_of_strings>0
{
for(n=1;n<=number_of_strings;n+=1)
show_message(string(msg_string[n]))
}

But the problem with this is it displays an individual message for each skill decreased.
I'd want the message to be like this:

Skill1 has decreased by 1
Skill2 has decreased by 1

All in the same message.
So what I want is a way to pool all strings from 1 to n into a single variable.
In maths the formula would look like this:

string=msg_string[1]+msg_string[2]+msg_string[3]+ ... +msg_string[n]

But you can't do that in GM, or at least I don't know how.
Sorry if that's unclear, and any help would be greatly appreciated.

Edited by Andyh444, 19 September 2010 - 03:44 PM.

  • 0

#2 smash ball

smash ball

    Volcanic Light

  • GMC Member
  • 1126 posts
  • Version:GM7

Posted 19 September 2010 - 02:38 PM

First, make a variable set to the number of skills.

for (i=1, i<number_skills, i+=1)
{ main_string+="Skill" + string(i) + " has decreased by 1"
main_string+=# //adds new line
}
Now display the string.
  • 0

#3 Andyh444

Andyh444

    GMC Member

  • GMC Member
  • 60 posts

Posted 19 September 2010 - 03:02 PM

First, make a variable set to the number of skills.

for (i=1, i<number_skills, i+=1)
{ main_string+="Skill" + string(i) + " has decreased by 1"
main_string+=# //adds new line
}
Now display the string.


thanks smash ball, but unless I'm doing something wrong that doesn't work
  • 0

#4 FoxInABox

FoxInABox

    GMC Member

  • GMC Member
  • 5400 posts
  • Version:GM:Studio

Posted 19 September 2010 - 03:21 PM

string=msg_string[1]+msg_string[2]+msg_string[3]+ ... +msg_string[n]

But you can't do that in GM, or at least I don't know how.

you can do that in GM, exaclty like that, it is just missing the spaces between +'#'+ .. or you can do it with a loop:
if number_of_strings>0
{
str=''; // make a empty string
for(n=1;n<=number_of_strings;n+=1)
 str+=msg_string[n] + '#'; // add line by line into it
show_message(str)
}

  • 0

#5 Andyh444

Andyh444

    GMC Member

  • GMC Member
  • 60 posts

Posted 19 September 2010 - 03:43 PM

string=msg_string[1]+msg_string[2]+msg_string[3]+ ... +msg_string[n]

But you can't do that in GM, or at least I don't know how.

you can do that in GM, exaclty like that, it is just missing the spaces between +'#'+ .. or you can do it with a loop:
if number_of_strings>0
{
str=''; // make a empty string
for(n=1;n<=number_of_strings;n+=1)
 str+=msg_string[n] + '#'; // add line by line into it
show_message(str)
}


Hey wow it works now! Thanks, FoxInABox.
I guess it didn't work with smash ball's code because there wasn't a str='' part, so GM didn't know it was a string variable, or something like that.
Anyway, cool that solves that then
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users