Powered by Invision Power Board

 
    Reply to this topicStart new topicStart Poll

> Variable in Mid-string, GM7
United States
Mike Shinoda
Posted: Oct 18 2009, 12:27 PM
Quote Post


Aka Artic
[*][*]

Group Icon
Group: Members
Posts: 802
Member No.: 3598
Joined: 12-April 07

Status: (0d) [--]


Hey, I need to know how to set a variable in the middle of a string
something like
var_string = "Whats going down [delay=5] yall?"
But I need to make [delay=5] be executed as only changing a value, not appearing the the string. Delay is the variable determingin the text speed

So it would be like
(at the speed of 2) Whats going down (at the speed of 5) yall?

I dont care how complicated the code is, does anyone know how to do this?


--------------------
rain.

AKA Artic

I'm gonna miss you ol' pal. See you guys in the 3.0.
PMEmail PosterUsers WebsiteIntegrity Messenger IMAOLYahooMSN
Top
United States
Ianprime0509
Posted: Oct 18 2009, 12:34 PM
Quote Post


My favorite E3 game so far
[*][*]

Group Icon
Group: Members
Posts: 488
Member No.: 3316
Joined: 17-February 07

Status: (0d) [--]


You could do something like:
CODE
var_string = "Whats going down ";
delay = 5;
var_string += "yall?"


But this does limit you to having to declare the string outside of whatever function you're using.


--------------------

user posted imageuser posted imageuser posted image
Signature version 3.0
PMEmail Poster
Top
Unspecified
exenefevex
Posted: Oct 18 2009, 01:02 PM
Quote Post


Regular
[*][*][*]

Group Icon
Group: Members
Posts: 258
Member No.: 3660
Joined: 19-April 07

Status: (0d) [--]


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


--------------------
PM
Top
India
Char
Posted: Oct 18 2009, 01:06 PM
Quote Post


fad was bad
[M][*][*]

Group Icon
Group: Admins
Posts: 2123
Member No.: 2856
Joined: 25-October 06

Status: (0d) [--]


QUOTE (exenefevex @ Oct 18 2009, 11:32 PM)
//must be converted to number first -- forgot exact GML instruction

real()


--------------------
aa this broke


Make your own | If a level is breaking the rules, note the ID and PM me.
Reference (thanks Frogjester!)
PMEmail PosterUsers WebsiteAOLYahooMSN
Top
United States
Mike Shinoda
Posted: Oct 18 2009, 01:27 PM
Quote Post


Aka Artic
[*][*]

Group Icon
Group: Members
Posts: 802
Member No.: 3598
Joined: 12-April 07

Status: (0d) [--]


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.
PMEmail PosterUsers WebsiteIntegrity Messenger IMAOLYahooMSN
Top
Unspecified
exenefevex
Posted: Oct 18 2009, 01:31 PM
Quote Post


Regular
[*][*][*]

Group Icon
Group: Members
Posts: 258
Member No.: 3660
Joined: 19-April 07

Status: (0d) [--]


QUOTE (Mike Shinoda @ Oct 18 2009, 01:27 PM)
Im assuming that large code replaces the alarm[0] event?

Yeah.

Mind you I haven't tested anything and it's probably going to break miserably, but for now I'd plug that into alarm[0] and see what happens.


--------------------
PM
Top
United States
Mike Shinoda
Posted: Oct 18 2009, 02:11 PM
Quote Post


Aka Artic
[*][*]

Group Icon
Group: Members
Posts: 802
Member No.: 3598
Joined: 12-April 07

Status: (0d) [--]


Well, it keeps giving this one error. I think its because Im not defining some variables correctly. You gave me Variables "position" and "c". How do I define these in the create event without causing some sort of error? Also, what exactly do these vars stand for? (sorry)

ALSO when I define the variables as 0 in create, it says "error in real()"


--------------------
rain.

AKA Artic

I'm gonna miss you ol' pal. See you guys in the 3.0.
PMEmail PosterUsers WebsiteIntegrity Messenger IMAOLYahooMSN
Top
India
Char
Posted: Oct 18 2009, 02:21 PM
Quote Post


fad was bad
[M][*][*]

Group Icon
Group: Admins
Posts: 2123
Member No.: 2856
Joined: 25-October 06

Status: (0d) [--]


post the error(s)


--------------------
aa this broke


Make your own | If a level is breaking the rules, note the ID and PM me.
Reference (thanks Frogjester!)
PMEmail PosterUsers WebsiteAOLYahooMSN
Top
United States
Mike Shinoda
Posted: Oct 18 2009, 02:23 PM
Quote Post


Aka Artic
[*][*]

Group Icon
Group: Members
Posts: 802
Member No.: 3598
Joined: 12-April 07

Status: (0d) [--]


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.
PMEmail PosterUsers WebsiteIntegrity Messenger IMAOLYahooMSN
Top
Unspecified
exenefevex
Posted: Oct 18 2009, 02:30 PM
Quote Post


Regular
[*][*][*]

Group Icon
Group: Members
Posts: 258
Member No.: 3660
Joined: 19-April 07

Status: (0d) [--]


Position is your position progress within the textbox. It starts at 0 1! see following posts.

C is the next character to be added to draw_string unless that character is '%'. I originally called it "char" but there are already several variables, functions, and people all named char. C is a temporary variable, so you should declare it using var at the beginning of alarm[0]. You do not need to give it an initial value because it's set moments later.

delay = real(string_char_at(string_to_draw,position+1)) should not be causing an error in real. But just in case:
CODE
show_error(string_to_draw+", "+string(position+1)+", "+string_char_at(string_to_draw,position+1),false);
place that line immediately before the line with real() in it so we can see what's happening.

This post has been edited by exenefevex on Oct 18 2009, 03:08 PM


--------------------
PM
Top
United States
Mike Shinoda
Posted: Oct 18 2009, 03:00 PM
Quote Post


Aka Artic
[*][*]

Group Icon
Group: Members
Posts: 802
Member No.: 3598
Joined: 12-April 07

Status: (0d) [--]


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)


--------------------
rain.

AKA Artic

I'm gonna miss you ol' pal. See you guys in the 3.0.
PMEmail PosterUsers WebsiteIntegrity Messenger IMAOLYahooMSN
Top
Unspecified
exenefevex
Posted: Oct 18 2009, 03:08 PM
Quote Post


Regular
[*][*][*]

Group Icon
Group: Members
Posts: 258
Member No.: 3660
Joined: 19-April 07

Status: (0d) [--]


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. wink.gif

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


--------------------
PM
Top
United States
Mike Shinoda
Posted: Oct 18 2009, 04:04 PM
Quote Post


Aka Artic
[*][*]

Group Icon
Group: Members
Posts: 802
Member No.: 3598
Joined: 12-April 07

Status: (0d) [--]


It works! Thanks to Retroxyz, exenefevex, and char(i guess?)


--------------------
rain.

AKA Artic

I'm gonna miss you ol' pal. See you guys in the 3.0.
PMEmail PosterUsers WebsiteIntegrity Messenger IMAOLYahooMSN
Top
India
Char
Posted: Oct 18 2009, 04:30 PM
Quote Post


fad was bad
[M][*][*]

Group Icon
Group: Admins
Posts: 2123
Member No.: 2856
Joined: 25-October 06

Status: (0d) [--]


lol what did i do


--------------------
aa this broke


Make your own | If a level is breaking the rules, note the ID and PM me.
Reference (thanks Frogjester!)
PMEmail PosterUsers WebsiteAOLYahooMSN
Top
United States
Mike Shinoda
Posted: Oct 18 2009, 07:04 PM
Quote Post


Aka Artic
[*][*]

Group Icon
Group: Members
Posts: 802
Member No.: 3598
Joined: 12-April 07

Status: (0d) [--]


QUOTE (Char @ Oct 18 2009, 04:30 PM)
lol what did i do

I'm using the auto-enter code you put up in the other topic


--------------------
rain.

AKA Artic

I'm gonna miss you ol' pal. See you guys in the 3.0.
PMEmail PosterUsers WebsiteIntegrity Messenger IMAOLYahooMSN
Top
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

  Topic Options Topic Options Reply to this topicStart new topicStart Poll

 




[ Script Execution time: 0.0664 ]   [ 13 queries used ]   [ GZIP Enabled ]   [ Server Load: 1.54 ]