Topic:   Gm Syntax Questions   (Read 13008 times)


0 Members and 1 Guest are viewing this topic.

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Gm Syntax Questions
« on: August 06, 2008, 11:47:14 AM »
I will post random syntax questions here at random times.

If you have a variable of:
"Hello my name is Gandolf."

How would you change the spaces to:
"Hello%my%name%is%Gandolf."

Then how would you change those back to spaces?

Also, is there a way to get a certain word from a string?

Like get purple from:
"green;yellow;red;purple;


Thanks
-Gandolf

P.S. In the text field, how would you write text a line down?
Like: print $line1$$ + $line2$$
« Last Edit: August 06, 2008, 11:51:11 AM by Gandolf »

Swamp7hing


  • GMG-er

  • **


  • Posts: 751

  • I come from the swamps.
Re: Gm Syntax Questions
« Reply #1 on: August 06, 2008, 12:21:32 PM »
Ahh, maybe I can help:

Make x = 1, then if x = 1 on saying that string, print a % where x would be. So it would look like:

PRINT "Hello""x""my""x""name"... etc

I'm not sure if this would do it, as I'm not the best GM programmer in the world. I've gotta catch up on that. :D

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: Gm Syntax Questions
« Reply #2 on: August 06, 2008, 01:02:02 PM »
Thats not exactly how it will work.

Code: [Select]
The player types a message... "Hi there!"

The message gets converted to "Hi%there!"

Message gets saved on Php.

Message received on Gm as "Hi%there!"

Message converted back to "Hi there!"

Message is printed.

Also, is there a way to get a certain word from a string?
 
Like get purple from:
"green;yellow;red;purple;


-Gandolf

Al Staffieri


  • GMG-er

  • **

  • no avatar

  • Posts: 452

  • I love GameMaker
Re: Gm Syntax Questions
« Reply #3 on: August 06, 2008, 02:09:43 PM »

' Convert " " to "%"
a$ = "Hello. My name is Al."
PRINT $a$$

x = 0
c$ = ""
REPEAT
  x = x + 1
  b$ = WORD$ a$ x
  IF b$ = a$ THEN EXIT REPEAT
  IF b$ = "" THEN EXIT REPEAT
  IF c$ <> "" THEN
    c$ = c$ + "%"
  END IF
  c$ = c$ + b$
END REPEAT

PRINT $c$$

' ----------

' Convert "%" to " "
' a$ = "Hello. My name is Al."
PRINT

a$ = c$
PRINT $a$$
x = 0
lenth = LEN a$

REPEAT
x = x + 1
b$ = MID$ a$ x 1
IF b$ = "%" THEN
  x = x - 1
  c$ = LEFT$ a$ x
  c$ = c$ + " "
  x = x + 2
  d$ = MID$ a$ X
  a$ = c$
  a$ = a$ + d$
ELSE
  c$ = a$
END IF
IF x => lenth THEN EXIT REPEAT
END REPEAT

PRINT $c$$

Al Staffieri


  • GMG-er

  • **

  • no avatar

  • Posts: 452

  • I love GameMaker
Re: Gm Syntax Questions
« Reply #4 on: August 06, 2008, 02:12:40 PM »
Quote
In the text field, how would you write text a line down?
Like: print $line1$$ + $line2$$

If you want it all on one line then use a semicolon
PRINT $line1$$;
PRINT $line2$$

Swamp7hing


  • GMG-er

  • **


  • Posts: 751

  • I come from the swamps.
Re: Gm Syntax Questions
« Reply #5 on: August 06, 2008, 02:40:41 PM »
Looks like you guys are coming along with this! Nice stuff!

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: Gm Syntax Questions
« Reply #6 on: August 06, 2008, 03:39:22 PM »
Thanks. Also, If I had a string as "Gandolf: Hello^George: Hi"
 
How would I cut the line in half and print it as:
 
Gandolf: Hello
George: Hi
 
 
-Gandolf

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: Gm Syntax Questions
« Reply #7 on: August 06, 2008, 09:22:50 PM »
I believe this would work:  var1$ = WORD$ var2$ x

Though if instead of spaces, I had ":" would it work?


-Gandolf

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: Gm Syntax Questions
« Reply #8 on: August 07, 2008, 02:42:56 PM »
Hey Al, the code you wrote doesn't work:

Quote
' Convert " " to "%"
a$ = "Hello. My name is Al."
PRINT $a$$
 
x = 0
c$ = ""
REPEAT
  x = x + 1
  b$ = WORD$ a$ x
  IF b$ = a$ THEN EXIT REPEAT
  IF b$ = "" THEN EXIT REPEAT
  IF c$ <> "" THEN
    c$ = c$ + "%"
  END IF
  c$ = c$ + b$
END REPEAT
 
PRINT $c$$



-Gandolf

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: Gm Syntax Questions
« Reply #9 on: August 07, 2008, 08:22:07 PM »
Nevermind. It works.


-Gandolf