| |
Variable in Mid-string, GM7
exenefevex |
|
Regular
![Super Happy Heart Badge [*]](https://archive.mfgg.net/html/badges/shappyheart.gif) ![Minigame Comp Winner Badge (1) [*]](https://archive.mfgg.net/html/badges/mcg1.gif) ![Secret Santa Badge [*]](https://archive.mfgg.net/html/badges/present.gif)

Group: Members
Posts: 258
Member No.: 3660
Joined: 19-April 07
Status: (0d)
![[--]](style_images/mfgg2_skin/warn_nosuspend.gif)

|
| QUOTE (Mike Shinoda @ Oct 18 2009, 12:27 PM) | | Delay is the variable determingin the text speed |
I'm assuming you're making an animated text box similar to this topic here. Pick an escape character such as %, and place both it and the new speed into the string as shown: | CODE | | var_string = "%2Whats going down %5yall?"; |
Because you don't want the speed modifier to appear, you will need to build your message one letter at a time, and you'll want to modify it to check for your escape character.
Here's a rough example which mashes up both of the examples in that other topic:
| CODE | c = string_char_at(string_to_draw,position); if(c!='%') { string_draw += c; position += 1; } else { delay = real(string_char_at(string_to_draw,position+1)); //thank you Char position += 2; } alarm[0] = delay;
|
if you want to be able to set variables other than delay, you'll need to be able to parse a more complicated escape sequence. Might be easiest to parse everything between two %'s and run execute_string on it, but that would be unsafe to use on user input.
This post has been edited by exenefevex on Oct 18 2009, 01:22 PM
--------------------
|
|
|
Mike Shinoda |
|

Aka Artic
![Super Happy Heart Badge [*]](https://archive.mfgg.net/html/badges/shappyheart.gif) ![Sprite Comp Top 5 Badge (1) [*]](https://archive.mfgg.net/html/badges/sct1.gif)

Group: Members
Posts: 802
Member No.: 3598
Joined: 12-April 07
Status: (0d)
![[--]](style_images/mfgg2_skin/warn_nosuspend.gif)

|
| QUOTE (exenefevex @ Oct 18 2009, 01:02 PM) | I'm assuming you're making an animated text box similar to this topic here. Pick an escape character such as %, and place both it and the new speed into the string as shown:
| CODE | | var_string = "%2Whats going down %5yall?"; |
Because you don't want the speed modifier to appear, you will need to build your message one letter at a time, and you'll want to modify it to check for your escape character.
Here's a rough example which mashes up both of the examples in that other topic:
| CODE | c = string_char_at(string_to_draw,position); if(c!='%') { string_draw += c; position += 1; } else { delay = real(string_char_at(string_to_draw,position+1)); //thank you Char position += 2; } alarm[0] = delay;
|
if you want to be able to set variables other than delay, you'll need to be able to parse a more complicated escape sequence. Might be easiest to parse everything between two %'s and run execute_string on it, but that would be unsafe to use on user input.
|
Im assuming that large code replaces the alarm[0] event?
--------------------
rain.AKA Artic I'm gonna miss you ol' pal. See you guys in the 3.0.
|
|
|
Mike Shinoda |
|

Aka Artic
![Super Happy Heart Badge [*]](https://archive.mfgg.net/html/badges/shappyheart.gif) ![Sprite Comp Top 5 Badge (1) [*]](https://archive.mfgg.net/html/badges/sct1.gif)

Group: Members
Posts: 802
Member No.: 3598
Joined: 12-April 07
Status: (0d)
![[--]](style_images/mfgg2_skin/warn_nosuspend.gif)

|
When I define "c" and "position" as 0
| CODE | ERROR in action number 1 of Alarm Event for alarm 0 for object object0:
Error in function real().
|
when I dont
| CODE | ERROR in action number 1 of Alarm Event for alarm 0 for object object0:
Error in code at line 1: c = string_char_at(string_to_draw,position);
at position 35: Unknown variable position
|
--------------------
rain.AKA Artic I'm gonna miss you ol' pal. See you guys in the 3.0.
|
|
|
exenefevex |
|
Regular
![Super Happy Heart Badge [*]](https://archive.mfgg.net/html/badges/shappyheart.gif) ![Minigame Comp Winner Badge (1) [*]](https://archive.mfgg.net/html/badges/mcg1.gif) ![Secret Santa Badge [*]](https://archive.mfgg.net/html/badges/present.gif)

Group: Members
Posts: 258
Member No.: 3660
Joined: 19-April 07
Status: (0d)
![[--]](style_images/mfgg2_skin/warn_nosuspend.gif)

|
| QUOTE (Mike Shinoda @ Oct 18 2009, 03:00 PM) | | CODE | ERROR in action number 1 of Alarm Event for alarm 0 for object object0:
%2Hello, %5World!, 1, % |
"hello, World!" is the message im using. But I dont get what this error means (Im not basic with GML, I just dont use this type of code)
|
show_error is basically show_message with a bunch of extra information thrown at you, that's why I had you use it. I made some edits to my original post so I can't be sure this is what you're seeing but here's what the message should mean: string_to_draw == "%2Hello, %5World!" position == 0 (or more precisely, position+1 == 1) We already know that the 0th character in string_to_draw is "%" (otherwise you wouldn't see this message) The (0+1)th character in string_to_draw is "%" This makes absolutely no sense, unless [opens gamemaker *type type type click*]AHA found your problem. Strings in GM7 are (apparently) one-indexed, not zero-indexed. Furthermore there's a bug in string_char_at in GameMaker, wherein instead of causing an error when index is 0, it returns the 1st character instead. This makes your script think it found a "%" before it actually did. Not good. But to solve your problem, all you have to do is initialize position to 1 instead of 0 in the create event. This post has been edited by exenefevex on Oct 18 2009, 03:30 PM
--------------------
|
|
|
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:
Track this topic
Receive email notification when a reply has been made to this topic and you are not active on the board.
Subscribe to this forum
Receive email notification when a new topic is posted in this forum and you are not active on the board.
Download / Print this Topic
Download this topic in different formats or view a printer friendly version.
[ Script Execution time: 0.0609 ] [ 14 queries used ] [ GZIP Enabled ] [ Server Load: 1.68 ]
| |