Page 1 of 1

Change Text using scrpt (Help)

PostPosted: Thu Nov 10, 2011 7:05 am
by micolord
See the alphabets? Clicking one of them will change the ' _ ' in the name frame.I now know how to use:
Code: Select all
sprintf(text, "%s", "value should be here") // i dont really know what does the '%s' for.

but my problem now is... I don't know how to use that to change the others text.

Image

Re: Change Text using scrpt (Help)

PostPosted: Thu Nov 10, 2011 7:49 am
by skydereign
Well, if you are just changing characters, I'd suggest using the characters. Essentially you have a variable that holds the cursor position (which is essentially the position in the array). Then you can just use string[var]='A', and similar. Whenever you type a new letter, that'll make the _ that was there something else, and then increase the variable (cursor position) so that when you type another, it changes the next.

Re: Change Text using scrpt (Help)

PostPosted: Thu Nov 10, 2011 8:43 am
by micolord
skydereign wrote:Well, if you are just changing characters, I'd suggest using the characters. Essentially you have a variable that holds the cursor position (which is essentially the position in the array). Then you can just use string[var]='A', and similar. Whenever you type a new letter, that'll make the _ that was there something else, and then increase the variable (cursor position) so that when you type another, it changes the next.


I suck. Didn't get a thing. Can you just please tell me how to change the character text with the same text with the character you have pressed.

Re: Change Text using scrpt (Help)

PostPosted: Thu Nov 10, 2011 8:50 am
by skydereign
I did exactly that. I already explained earlier how to change a character. I also regave the code to do so, namely the bit in bold.
skydereign wrote:Well, if you are just changing characters, I'd suggest using the characters. Essentially you have a variable that holds the cursor position (which is essentially the position in the array). Then you can just use string[var]='A', and similar. Whenever you type a new letter, that'll make the _ that was there something else, and then increase the variable (cursor position) so that when you type another, it changes the next.

Now, you've shown that you understand variables, so creating an int, and using it to determine which character to replace is the only thing else you need for this.

Re: Change Text using scrpt (Help)

PostPosted: Thu Nov 10, 2011 9:08 am
by micolord
My only problem now is how to change the other characters text using script, but here, here is what I am stack at:

Code: Select all
if (spacechar==0){
if (Name[0]=='_'){
if (lettercase==0){
Name[0] = 'a';
spacechar++;
   } else {
Name[0] = 'A';
  }
 }
}


I now only need is how to change the other character text.

Re: Change Text using scrpt (Help)

PostPosted: Thu Nov 10, 2011 9:16 am
by skydereign
I'd suggest reading my post again, but since I'm already typing a response might as well say it again. If you have a variable, an integer, then you can use it to determine which character to change. You know how you are changing the 0 character using [0]. You can change the 1 character with [1]. But, if you create an integer variable, you can use [var], and change var to whatever you want. In your case, you want it to start at 0, and each character you input, you increase by 1. That way the first character is [0], the second will be [1], and so on. But, all you need to do is have [var] and make sure to increase it.

Looking at your code though, a lot of those ifs aren't necessary. You can use the ordering of ASCII to your advantage, but I'll skip that and just show you the ternary operator.
Code: Select all
Name[0] = (lettercase==0) ? 'a' : 'A' ;

It uses the form, (condition ? do this : else do this). So, if the condition is true, it will execute the first bit (before the colon), but if it is false, it will return the second. So the above code will set Name[0] to a if lettercase is 0, otherwise it sets it to A.

Re: Change Text using scrpt (Help)

PostPosted: Thu Nov 10, 2011 9:39 am
by micolord
There are 6 '_' which there would be put the first letter you'd pick from the alphabet which means a limit of 6 character only that you can use for your name.... so now I created the variable called if spacechar to determine which to change from those 6 characters. If you click on letter 'A' the script would do: if this space is not taken then place the text which is letter A and if not find another space that is currently un used:

Code: Select all
if (spacebar==0){ // which means if first bar is empty then
Name[0] = 'A';
sprintf(text, '%s', Name[0]); // i need to know how to change the first bar text by this but this changes the thing you click
}


I already know the array stuff which you answered in my last question. Or I think I should use the activation event.

Re: Change Text using scrpt (Help)

PostPosted: Thu Nov 10, 2011 9:48 am
by skydereign
The point is, you don't want to use Name[0]. If you did that, then you can only change the first character in the string. If you use a variable, so Name[variable], you can have the same code change whichever character in the string. So, you have 6 characters in your string, all by default set to _. So, you need to click the letters 6 times. You want code that can make the 6 changes, without having to write new code for each new character. Therefore, if you use Name[variable], and change variable after each new character. With that you can make the string exactly what you want, with only one bit of code (instead of 6).

Now, to make the text change, you have to remember that Name[0] is a character, not a string. A string is an array of characters. So if you wanted to set the text you need to use Name.
Code: Select all
sprintf(text, "%s", Name);