techknight Well-Known Member Licensed User Longtime User May 31, 2018 #1 I would like to be able to do this, but for some reason the compiler keeps throwing a syntax error: Code: Copy lblPlayer2.Text = "No player in Slot: " & PlayerIndex + 1 Probably because the +1 on the end. See, I can do this in any other language except for this one for some reason unless I am doing it wrong? Maybe I need parenthesis? I am afraid if I put it in parenthesis that it would actually increment the variable by 1 instead of "referencing as it is plus 1" The PlayerIndex is 0 based, and the label I want 1 based. So if PlayerIndex is 0, I want the user to see "1" hence why I put the + 1 on the end. I really dont want to have to declare another variable and add another line of code if I dont have to. any ideas?
I would like to be able to do this, but for some reason the compiler keeps throwing a syntax error: Code: Copy lblPlayer2.Text = "No player in Slot: " & PlayerIndex + 1 Probably because the +1 on the end. See, I can do this in any other language except for this one for some reason unless I am doing it wrong? Maybe I need parenthesis? I am afraid if I put it in parenthesis that it would actually increment the variable by 1 instead of "referencing as it is plus 1" The PlayerIndex is 0 based, and the label I want 1 based. So if PlayerIndex is 0, I want the user to see "1" hence why I put the + 1 on the end. I really dont want to have to declare another variable and add another line of code if I dont have to. any ideas?
DonManfred Expert Licensed User Longtime User May 31, 2018 #2 Code: Copy lblPlayer2.Text = $"No player in Slot: ${PlayerIndex + 1}"$ Upvote 0
techknight Well-Known Member Licensed User Longtime User May 31, 2018 #3 Thanks, but can you explain what the $ is for so I can learn? Upvote 0
DonManfred Expert Licensed User Longtime User May 31, 2018 #4 techknight said: Thanks, but can you explain what the $ is for so I can learn? Click to expand... https://www.b4x.com/android/forum/threads/b4x-smart-string-literal.50135/ Upvote 0
techknight said: Thanks, but can you explain what the $ is for so I can learn? Click to expand... https://www.b4x.com/android/forum/threads/b4x-smart-string-literal.50135/
techknight Well-Known Member Licensed User Longtime User May 31, 2018 #5 That confused me mostly but I THINK I understand it. So, Will this physically increment the variable? or it will it display a reference of the function as if the variable had 1 added to it? but the variable remain as is? Just curious. Upvote 0
That confused me mostly but I THINK I understand it. So, Will this physically increment the variable? or it will it display a reference of the function as if the variable had 1 added to it? but the variable remain as is? Just curious.
DonManfred Expert Licensed User Longtime User May 31, 2018 #6 techknight said: Will this physically increment the variable? Click to expand... no- The "Value" in ${x} just output x Check #2 and #3 in the Tutorialthread. This should make it more clear Upvote 0
techknight said: Will this physically increment the variable? Click to expand... no- The "Value" in ${x} just output x Check #2 and #3 in the Tutorialthread. This should make it more clear
M Mahares Expert Licensed User Longtime User May 31, 2018 #7 Manfred is right on. You can actually test it with this: Code: Copy Dim PlayerIndex As Int=3 For i=0 To 4 Log($"No player in Slot: ${PlayerIndex + i}"$) Log(PlayerIndex) 'always displays 3 Next Upvote 0
Manfred is right on. You can actually test it with this: Code: Copy Dim PlayerIndex As Int=3 For i=0 To 4 Log($"No player in Slot: ${PlayerIndex + i}"$) Log(PlayerIndex) 'always displays 3 Next
Jeffrey Cameron Well-Known Member Licensed User Longtime User May 31, 2018 #8 I believe you may also get around the syntax error simply by enclosing the computation in parenthesis: Code: Copy lblPlayer2.Text = "No player in Slot: " & (PlayerIndex + 1) Upvote 0
I believe you may also get around the syntax error simply by enclosing the computation in parenthesis: Code: Copy lblPlayer2.Text = "No player in Slot: " & (PlayerIndex + 1)