reading out a string property

Is there anyway to do the following?

so i have and empty with a string property and when i press 1 on the keyboard it adds 1 to the string property and when i press 2 on the keyboard it adds 2 to the property and being a string property it doesnt add the two together like 1+2 = 3 instead it does 12 or if i kept pressing 1 and 2 it would be like 112221212221112212122 you get the idea andways is there anyway of taking and reading that string property digit by digit so if it read a 1 it would spit out a green cube and if it read a 2 it would spit out a blue cube so if the string property happend to have a sequence such as the following

122121 it would spit out the folling cubes in this order green blue blue green blue green.

anyways would there be away of doing this i know you can copy properties between two objects that have a property of the same name.

im using logic bricks also

With python this would be very easy, you would get the variable containing the string(you name it), then:

# Len = Length, i can have any name in fact(cube, x, y...). Self.create_cube would be a class function you would make.

for i in range(len(variable)):

     if i == 1: self.create_cube('green')

     else: self.create_cube('blue')

I would not advise logic bricks if your project is ambitious.

so will this work if i have a long eray of numbers in the same string like 112212121

Of course it would, the for loop would check each component of the string, in your case each number, also you string array is quite small compared with what python + even non modern computers can do.

ok thank you so i just have a always with a python controller to continually run it?

Never run a code when it isn’t needed, specially for loops and such. It depends on when you need to create these cubes, if only once, only once at the startup, if they can be created anytime among other things.

Give more details about where/when you would need to deploy these cubes.

i need them to be deployed just when ever or constant basically. or when i press a button.

Could the same thing be done with letters?Because i wanted to use letters in a book to place down different types of enemys in a game.But i wanted it also to place down buildings and weapons this way also.
That would make making games a lot easier and you could change the game really easy.

The same for letters.

About mrn cubes, for random behavior, create timers with a random target time; after the timer target time is met, call that function with that python for loop only once, and restart the timer from the current OS time. For constant behavior, do a timer with python, but now, use non random target time, it will deploy cubes at fixed time intervals.

I do not know if python/BGE already comes with this timers functionality, I had to do mine myself; watch out to the fact which python os time retrieval command on windows is different from the other os’s; not paying attention to that will give you inaccurate timers when your game is run at different os’s.

In the case of pressing button, just make a conditional, if the button is pressed, deploy cubes function is called; if just the start of the key press should deploy cubes, there is the BGE logic.KX_INPUT_JUST_ACTIVATED to do this task.

well i dont want to be randome but basically what i need it for like a computer type thing where i can inpute a sequance of 1’s and 2’s and then it will read that out kinda like code and do surtan things for each.