GameSalad

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

String concatenation only can assign first element.

TheDiabolicalMr4DeeTheDiabolicalMr4Dee Posts: 15Member
I created and attribute game.myName yet when I try to assign a concatenated string to it <char1>..<char2>..<char3> it only displays the first character. thus doing a displayText of game.myName I get <char1>

Comments

  • firemaplegamesfiremaplegames Posts: 3,206Member
    I just tried it and it works fine.

    Make sure you are choosing your attributes from the drop-down menu,i.e:

    myText = game.char1..game.char2..game.char3
  • i tried putting the concatenation in quotes but it returned gobblygook:

    vars['self.attributes.id572726']..vars['self.attributes.909518']. . . .
  • firemaplegamesfiremaplegames Posts: 3,206Member
    What exactly are you trying to concatenate?

    game.char1 = A
    game.char2 = B
    game.char3 = C

    game.myName = game.char1..game.char2..game.char3

    Display Text: game.myName will display ABC
  • hmmm. the only difference is that my strings were not on the game level. whereas your string is:

    mytext=game.char1..game.char2..

    mine are local:

    mytext=self.char1..self.char2.....self.char12

    basically I reimplemented your keyboard example for multiple text items so I made char1...char12 local to each actor consisting of a dislayText behavior, where the actors are named displayNameText, displaySchoolText . . etc. maybe i should try just making multiple sets of global attributes

    myName=game.nameLetter1..game.nameletter2..game.nameletter3
    mySchool=game.schoolLetter1..game.schooLetter2..gameschoolLetter3
  • I just need to have the player type in their name and school. the keyboard works but I can't get the 12character max string to display anymore than the first character after user types it in.
  • jessicaleahyjessicaleahy Posts: 144Member
    I just tried it and it works great.
  • yeah. looks like global is more reliable than local scope so this:

    mytext=self.char1..self.char2.....self.char12

    is not as predictable as:

    myName=game.nameLetter1..game.nameletter2..game.nameletter3
    mySchool=game.schoolLetter1..game.schooLetter2..gameschoolLetter3

    Also I dont think the actor that contained the attribute was the prototype. It was an instance of the rototype in a scene. so I just deleted it and started fresh. hope this helps anyone having wierd scoping problems. My advice . . . when in doubt, go global :0)
  • jessicaleahyjessicaleahy Posts: 144Member
    Yes. You have a great point there. Going global is actually the best choice if you are not sure what to do.
This discussion has been closed.