Topic:   Scripting Command Help   (Read 27714 times)


0 Members and 1 Guest are viewing this topic.

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Scripting Command Help
« on: May 29, 2008, 03:07:24 PM »
Hey, I need a little help with the GameMaker scripting commands on a project I am working on...

Here they are:

(1) Create a Sprite
(2) Move a Sprite
(3) Make a Timer
(4) Detect a Arrow Key (If uparrow is pressed then...)
(5) And finally, how to Change a Sprite's Image


Thanks, hope you guys can answer these.

-Gandolf

Al Staffieri


  • GMG-er

  • **

  • no avatar

  • Posts: 452

  • I love GameMaker
Re: Scripting Command Help
« Reply #1 on: May 29, 2008, 03:59:41 PM »
(1) create a sprite
SPRITE spriteNumber x y fileName$
Draws the sprite at the specified x, y location. After you've drawn a sprite once, you can leave out fileName$ for further sprite drawing with that sprite number to speed up drawing of the sprite. To hide a sprite, use a negative number for <spriteNumber> with no other parameters.

(2) Move a sprite
See above. leave out fileName$ and draw the srprite whereever you want it. GameMaker uses only one command for both loading and showing sprites.

(3) Make a Timer
I think this is the same as SC
ON TIMER x
  do stuff
END TIMER

(4) Detect arrow keys
Use ON KEYDOWN. There's a built in variable named keyDown$ that is always set to the current key being pressed.
ON KEYDOWN
 IF keyDown$ = "DOWNARROW" THEN
    blah blah
  END IF
END KEYDOWN

(5) How to change a sprites image.
See #1 above.

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: Scripting Command Help
« Reply #2 on: May 29, 2008, 07:06:28 PM »
Thanks, though I ran into a few problems.

(2) How do you just push a sprite without recreating it? Recreating it every 2 Mili-seconds on my timer would cause massive havoc and destruction on my computer.

If you are wondering, I'm trying to convert the Epic Scrolling Nav Engine to GM.

-Gandolf

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: Scripting Command Help
« Reply #3 on: May 29, 2008, 07:17:08 PM »
Does this look right?

Code: [Select]
LET movex = 0 
LET movey = 0
 
SPRITE 1 -1250 -1250 star$
 
SPRITE 3 285 130 ship$
 
ON TIMER 2 //The background moves every 2 miliseconds
SPRITE 1 movex movey
END TIMER
//When Press an Arrow Key
ON KEYDOWN
IF KeyDown$ = "UPARROW" THEN 
SPRITE 3 285 130 ship$ //changes ship direction to Up
   IF movey < 20 THEN  //Max speed of ship
 LET movey = movey + 1 //Acceleration of Ship
ELSE IF KeyDown$ = "DOWNARROW" THEN 
SPRITE 3 285 130 shipdown$ //changes direction to down
   IF movey > -20 THEN  
 LET movey = movey - 1  
ELSE IF KeyDown$ = "LEFTARROW" THEN
SPRITE 3 285 130 shipleft$ //changes direction to left
   IF movex < 20 THEN  
 LET movex = movex + 1  
ELSE IF KeyDown = "RIGHTARROW" THEN  
SPRITE 3 285 130 shipright$//changes direction to right
   IF movex > -20 THEN  
 LET movex = movex - 1  
   END IF  
END KEYDOWN


Also...   If it is could you please compile it into a program and post here? I have the sprite pics, though I don't own GM so I can't do it myself.


Thanks Al,

-Gandolf

Tireas Dragon


  • GMG Extraordinaire

  • ***


  • Posts: 1626

  • Trying to recover from my shattered screen.
Re: Scripting Command Help
« Reply #4 on: May 29, 2008, 08:03:07 PM »
Well you can't have the "//'s" they don't work in GM I don't see how this wold work tho but its your code here's what I get when I convert it to GM. The loop script is what makes the timer repeat they don't do very well repeating in GM.

Code: [Select]
Under Loop Script

IF set = 0 THEN
  set = 1
  LET movex = 0
  LET movey = 0

  SPRITE 1 -1250 -1250 star$

  SPRITE 3 285 130 ship$

ON KEYDOWN
IF keydown$ = "UPARROW" THEN
  SPRITE 3 285 130 shipup$
  IF movey < 20 THEN LET movey = movey + 1
END IF
IF keydown$ = "DOWNARROW" THEN
  SPRITE 3 285 130 shipdown$
  IF movey > -20 THEN LET movey = movey - 1
END IF
IF keydown$ = "LEFTARROW" THEN
  SPRITE 3 285 130 shipleft$
  IF moveX > -20 THEN LET movex = movex - 1
END IF
IF keydown$ = "RIGHTARROW" THEN
  SPRITE 3 285 130 shipright$
  IF moveX < 20 THEN LET moveX = moveX + 1
END IF
END KEYDOWN

END IF

IF go = 0 THEN
go = 1
ON TIMER 2
  go = 0
  SPRITE 1 movex movey
END TIMER
END IF
I must be dreaming (wake up me wake up) How could this have happened. Tireas' cry when he found his computer fallen over in his chair with it's screen shattered.

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: Scripting Command Help
« Reply #5 on: May 29, 2008, 08:26:57 PM »
Hmm...  Can you compile it in a GM App and post it up? I wonder how it will act...

Thanks,
-Gandolf

Tireas Dragon


  • GMG Extraordinaire

  • ***


  • Posts: 1626

  • Trying to recover from my shattered screen.
Re: Scripting Command Help
« Reply #6 on: May 29, 2008, 11:49:41 PM »
I highly doubt it will work but the navigation system will be really good if it does work. Just set what your variables are in card 1 with the GM demo

link removed
« Last Edit: May 30, 2008, 10:51:25 AM by Tireas_Dragon »
I must be dreaming (wake up me wake up) How could this have happened. Tireas' cry when he found his computer fallen over in his chair with it's screen shattered.

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: Scripting Command Help
« Reply #7 on: May 30, 2008, 12:39:44 AM »
Hm. Doesn't seem to work, should though. The sprites don't show up on the screen...   ...or do they...? Maybe they are off somewhere outside the view of the player. I'm not sure, should work though.

Al, what do you think?


Thanks for compiling it, Tireas Dragon

-Gandolf

Tireas Dragon


  • GMG Extraordinaire

  • ***


  • Posts: 1626

  • Trying to recover from my shattered screen.
Re: Scripting Command Help
« Reply #8 on: May 30, 2008, 09:59:41 AM »
You have to use GM go on card 1 and set your sprite names.
star$ sprite
ship$ sprite
shipup$ sprite
shipleft$ sprite
shipdown$ sprite
shipright$ sprite
you should set what their file names are on card 1
I must be dreaming (wake up me wake up) How could this have happened. Tireas' cry when he found his computer fallen over in his chair with it's screen shattered.

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: Scripting Command Help
« Reply #9 on: May 30, 2008, 10:06:11 AM »
Haha, sorry. My mind must of been somewhere else when I was doing this. Thanks TD. I'm going to try again.

-Gandolf

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: Scripting Command Help
« Reply #10 on: May 30, 2008, 10:15:07 AM »
For some reason, I can't get Gm to do anything.

Here are the sprites if you want to try it yourself.

http://www.mediafire.com/?dxwyy25tjz1

I guess I'm just not use to Gm Scripting.

-Gandolf

Tireas Dragon


  • GMG Extraordinaire

  • ***


  • Posts: 1626

  • Trying to recover from my shattered screen.
Re: Scripting Command Help
« Reply #11 on: May 30, 2008, 10:51:00 AM »
K this should work.

http://www.mediafire.com/?fo1j9kzjwmt

I forgot to put $$ around the variable sprite names.
I must be dreaming (wake up me wake up) How could this have happened. Tireas' cry when he found his computer fallen over in his chair with it's screen shattered.

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: Scripting Command Help
« Reply #12 on: May 30, 2008, 11:17:37 AM »
Hah!   :D

It works!

Thanks TD!

Too bad its kinda slow and blocky. I wonder if there is a way we can optimize the code to speed it up.

-Gandolf
« Last Edit: May 30, 2008, 11:20:41 AM by Gandolf »

Tireas Dragon


  • GMG Extraordinaire

  • ***


  • Posts: 1626

  • Trying to recover from my shattered screen.
Re: Scripting Command Help
« Reply #13 on: May 30, 2008, 12:53:50 PM »
I had to add 2 new variables for that. Movespeed X&Y so the ship would continue moving. I don't know how to fix the blockyness but I'll see what I can do.
I must be dreaming (wake up me wake up) How could this have happened. Tireas' cry when he found his computer fallen over in his chair with it's screen shattered.

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: Scripting Command Help
« Reply #14 on: May 30, 2008, 01:00:20 PM »
Ok  :)

-Gandolf