DS Game Maker Coding Reference
This is an index of all the in-built functions, event handlers, and property codes of DS Game Maker. You can use these anywhere in Action Blocks, DBAS Scripts and C Scripts.
As well, you can find even more useful codes from the PAlib Functions Reference.
|[Me]||The Instance ID number of the object that is using this code.
E.g. Delete_Instance([Me]) deletes the object using this code.
|[X]||The X position of the object that is using this code.|
|[Y]||The Y position of the object that is using this code.|
|[Width]||The width measured in pixels of the object using this code.|
|[Height]||The height measured in pixels of the object using this code.|
|[VX]||The horizontal velocity of the object that is using this code.|
|[VY]||The vertical velocity of the object that is using this code.|
|[OriginalX]||The object's X position that it was originally created at.|
|[OriginalY]||The object's Y position that it was originally created at.|
|[Screen]||The screen that the object exists on. Is either 1 for the top screen or 0 for the bottom.|
Object Instance Properties
DS Game Maker assigns a unique instance ID number to every object in a game room. Thus, the following property codes allow you to reference the properties of a particular object using the corresponding code and its instance ID number.
|Instances[ID].X||The X position of the object with the provided instance ID.|
|Instances[ID].Y||The Y position of the object with the provided instance ID.|
|Instances[ID].Width||The width of the object with the provided instance ID.|
|Instances[ID].Height||The height of the object with the provided instance ID.|
|Instances[ID].VX||The horizontal velocity of the object with the provided instance ID.|
|Instances[ID].VY||The vertical velocity of the object with the provided instance ID.|
|Instances[ID].OriginalX||The X position that the object with the provided instance ID was originally created at.|
|Instances[ID].OriginalY||The Y position that the object with the provided instance ID was originally created at.|
|Instances[ID].Frame||The current sprite frame number of the object with the provided instance ID.|
|Instances[ID].Screen||The screen that the object with the provided instance ID exists on. Is either 1 for the top screen or 0 for the bottom.|
|Instances[ID].EName||The name of the object with the provided instance ID.|
|Instances[ID].InUse||Whether the provided instance ID is in use by an object in the room or not (1 for true, 0 for false).|
Room and Screen Properties
|Top_Screen||The top screen number which is "1".|
|Bottom_Screen||The bottom screen number which is "0".|
|RoomData.TopX||The X position of the room's top screen camera view.|
|RoomData.TopY||The Y position of the room's top screen camera view.|
|RoomData.TopWidth||The width of the current room's top screen area.|
|RoomData.TopHeight||The height of the current room's top screen area.|
|RoomData.BottomX||The X position of the room's bottom screen camera view.|
|RoomData.BottomY||The Y position of the room's bottom screen camera view.|
|RoomData.BottomWidth||The width of the current room's bottom screen area.|
|RoomData.BottomHeight||The height of the current room's bottom screen area.|
|RoomSeconds||How many seconds have passed since the Room started.|
|RoomFrames||How many frames have passed since the Room started (DS Game Maker Games run at 60 frames per second).|
|Seconds||How many seconds have passed since the Game started.|
|Frames||How many frames have passed since the Game started (DS Game Maker Games run at 60 frames per second).|
|CurrentRoom||The room index number.|
|RoomCount||The number of rooms in your DS Game Maker project.|
These codes provide a value based on whether a certian event happened or is happening. Like pressing a button on the Nintendo DS or moving the DS's stylus on its touchscreen.
The available buttons on the Nintendo DS are:
Up, Down, Left, Right, A, B, X, Y, R, L, Start, Select.
|Pad.Newpress.Button||Whether the provided button has been pressed or not. Is true only once at the time of the event.|
|Pad.Held.Button||Whether the provided button is being held or not. Is true for as long as the button is being held.|
|Pad.Released.Button||Whether the provided button has been released or not. Is true only once at the time of the event.|
|Stylus.Newpress||Whether the stylus has pressed anywhere on the touchscreen. Is true only once at the time of the event.|
|Stylus.Held||Whether the stylus is being held on the touchscreen. Is true for as long as the stylus is being held on the touch screen.|
|Stylus.Released||Whether the stylus has been released from anywhere on the touchscreen. Is true only once at the time of the event.|
|Stylus.DblClick||Whether the stylus has double pressed anywhere on the touchscreen. Is true only during the 2nd or later press done in quick sucession.|
|Stylus.X||The X position where the stylus is currently touching or has last touched the touchscreen.|
|Stylus.Y||The Y position where the stylus is currently touching or has last touched the touchscreen.|
If you have just one instance of an object, this function returns its ID which you can use in other functions. If there is more than one instance, the first ID will be returned.
Dim ID As Integer = Get_Single_ID(ball) Delete_Instance(ID)
Returns the next available instance ID that you can use to create an object. When you create an object, you have to provide an instance ID for it (where you want it to go in the instances array). If you create and delete many objects, you can lose track of what positions are free. In these cases use this function. If you don't care about what instance number an object gets, use this function for the instance ID every time you create an object.
Create_Object(SofaObject, NextInstance(), Top_Screen, 32, 32) Create_Object(DoorObject, NextInstance(), Top_Screen, 64, 64)
Detects the collision of 2 objects, specified by their instance numbers. This is the function used for the 'If Collision' event. You cannot provide the names of 2 objects like this: Is_Sprite_Collision(ball, paddle), you must use their instance IDs. See the function Get_Single_ID.
Dim BulletID As Unsigned Byte = Get_Single_ID(Bullet_Object) Dim PlayerID As Unsigned Byte = Get_Single_ID(Player_Object) If Is_Sprite_Collision(BulletID, PlayerID) Delete_Instance(BulletID) End If
Very similar to the function Is_Sprite_Collision but a collision is only detected if the mid-point of an instance intersects the boundary of another. This is more useful for non-square objects.
Object_Under_Point(Screen, X, Y, ObjectName)
Returns whether there is an instance of ObjectName under a specified point.
Object_Under_H_Line(Screen, X1, X2, Y, ObjectName)
Returns whether there is an instance of ObjectName under the line specified with the co-ordinates (horizontal line; so Y applies to both X points).
Object_Under_V_Line(Screen, Y1, Y2, X, ObjectName)
Returns whether there is an instance of ObjectName under the line specified with the co-ordinates (vertical line; so X applies to both Y points).
Allows the instance to be dragged about with the Stylus. This function must be called every frame; therefore it must be called in a Step event.
Animate(InstanceID, FirstFrame, LastFrame, FPS)
Animates an instance (based upon the frames in its Sprite). The first argument is the instance number to animate. The second is the start frame, the first frame being 0 (not 1!). The fourth argument is 'frames per second' and it means how many frames should cycle visually within 1 second.
Determines whether an instance appears flipped vertically or not. The last argument should be true or false.
Determines whether an instance appears flipped horizontally or not. The last argument should be true or false.
Create_Object(ObjectName, InstanceID, Screen, X, Y)
Creates an instance of an Object. For Screen, use Top_Screen or Bottom_Screen. InstanceID can be NextInstance() if the next free ID is not known. You can have up to 128 objects in a room at once.
Set_Sprite(InstanceID, "SpriteName", DeleteOldSprite)
Sets the Sprite of the provided instance. The Sprite Name should be enclosed in quotes. DeleteOldSprite is a boolean value that is used mostly when DSGM calls the function. It usually always takes a value of true.
Deletes the selected instance.
Returns the X Position of the instance.
Returns the Y position of the instance.
Sets the X Position of an instance.
'Sets the X position of the first Ball object in the room to 64: Set_X(Get_Single_ID(Ball), 64) 'Sets the X position of whatever object is in instance slot 0 to 64: Set_X(0, 64)
Sets the Y Position of an instance.
Set_XY(InstanceID, X, Y)
Sets the X and Y Positions of an instance.
Sets the animation Frame of the instance. The first frame is number 0.
Returns the animation Frame of the instance.
Returns the number of instances of the specificed object.
'Breakout type game Dim Count As Unsigned Byte = Count_Instances(BrickObject) If Count = 0 Goto_Next_Room() End If
Text functions require the X and Y Positions to be provided in Tiles.
Draw_Health(Screen, XTiles, YTiles)
Draws the 'health' variable on the selected screen at the provided X and Y tile co-ordinates.
Draw_Lives(Screen, XTiles, YTiles)
Draws the 'lives' variable on the selected screen at the provided X and Y tile co-ordinates.
Draw_Score(Screen, XTiles, YTiles)
Draws the 'score' variable on the selected screen at the provided X and Y tile co-ordinates.
Draw_String(Screen, XTiles, YTiles, StringVariable)
Draws a Sting variable at the specified X and Y tile co-ordinates on the specificed screen. The variable must be declared in the Script or Global Variable/Arrays/Structures managers as a 'String' type.
Dim MyName As String MyName = "James" Draw_String(Top_Screen, 1, 1, MyName)
Draw_Variable(Screen, XTiles, YTiles, VariableName, IsFloat)
Draws the value of a Variable. The last argument, IsFloat, takes either true or false. Use 'true' for a floating (decimal number). For types such as Integer or Unsigned Byte, use false.
Set_BG_Scroll(Screen, Layer, X, Y)
Scrolls the loaded background to the specificed X and Y co-ordinates. You can load 4 backgrounds onto the screen from 0 to 3 so there is a Layer argument for which layer to scroll with the function. If you scroll past the constraints of the background (greater X or Y than the width or height), the background may repeat or show corrupt data. If the function does not do anything, check the Layer and that in the room 'Scroll BG with Camera' is not checked because this will overwrite the work of this function. The default Layer number is 2, for backgrounds placed on the screens within DS Game Maker.
Draw_Text(Screen, XTiles, YTiles, Text)
Draws text at the specified X and Y tile co-ordinates on the specificed screen. The text must be enclosed in quotes and you cannot use a variable. To do that see Draw_String.
'Length of "Hello!" Dim Length as Integer = 6 'Centering algorithm Dim X as Integer = (32/2) - (Length/2) Dim Y as Integer = (24/2) - 1 Draw_Text(Top_Screen, X, Y, "Hello!")
Set_Camera_XY(Screen, X, Y)
Sets the position of the camera in the room. Moving the camera to the right, for example, shifts plotted objects to the left. Objects still retain their X and Y co-ordinates after camera moving; the offset is only visual. You can compute the locations of objects relative to the physical screen borders by using the variables RoomData.TopX, (..) TopY, BottomX, BottomY.
Dim XPos as Integer = 0 Dim YPos as Integer = 0 If Pad.Newpress.Left XPos -= 1 End If If Pad.Newpress.Right XPos += 1 End If Set_Camera_XY(Bottom_Screen, XPos, YPos)
Returns the X position of the Camera.
'Move the camera to the right Set_Camera_XY(Top_Screen, Get_Camera_X(Top_Screen) + 5, Get_Camera_Y(Top_Screen))
Returns the Y position of the Camera.
You specify the number of sides of a dice which is then thrown. Use this function to test the probability of the event happening with the supplied sides. If the dice is thrown and lands on 1, the function returns true, otherwise false. For example when the ball hits a brick you can provide a particular 'chance' of a bonus score.
If Test_Chance(10) '1 in 10 times (random), these functions will run... End If
Returns whether the first number is divisible by the second (with the answer being integral). Arguments of 10, 5 return true but 19, 6 return false.
Is_Position_Free(Screen, X, Y)
Returns if a position on a collision map background is free (is magenta), at the specified X and Y co-ordinates. Use in conjuction with the action 'Load Collision Map'.
Is_Position_Occupied(Screen, X, Y)
Returns if a position on a collision map background is occupied (is not magenta), at the specified X and Y co-ordinates. Use in conjuction with the action 'Load Collision Map'.
Returns a random number between the provided constraints. Numbers can be negatively signed. For better random numbers, use a physical Nintendo DS.
Sets a String variable to the provided value. This is a rare function to have to use as DBAS automatically does this when you do an = assignment for a String.
Set_String(FirstName, "James") Set_String(LastName, "Garner")
Returns true if the strings are equal, and false if they are not.
Dim MyName as string = "James" Dim HisName as string = "James" If Strings_Same(MyName, HisName) Draw_Text(Top_Screen, 1, 1, "Names are the same.") Else Draw_Text(Top_Screen, 1, 1, "They are different.") End If
Pauses the specified Alarm (0 - 31). Pause takes true or false; true to pause the alarm and false to unpause it.
Sets the time of the specified Alarm (0 - 31) and activates it.
Goes to the next room from the current room, if another room exists.
Go to a Specific Room
Though there is not one dedicated function for achieving this in DS Game Maker, you can use the below code to switch to a specific room using the room's name.
CurrentRoom = Room_Get_Index("RoomName"); RoomFrames = 0; RoomSeconds = 0; RoomName();
Streams the provided Background sound. Use in a 'Step' Event.
Stops the Background (MP3) sound from playing.
Pauses the current playing Background sound. Due to the nature of the streaming, use with care if you plan to create and delete objects that stream the sound.
Unpauses the current playing Background sound; does the opposite of the above.
Sets the looping of the Background sound. Provide a boolean value such that 'true' makes the Background sound play again at the end, and 'false' does not.
Stops all sound effects from playing.
Sets the master volume for all sounds.
Sets the horizontal panning of all sounds. The Panning parameter ranges from -64 to 64. -64 is far-left panning and 64 is far right; 0 being the mid-point as default.
The following functions were originally only available in the Pro Edition of DS Game Maker but as of DS Game Maker 5.20 they are unlocked by default.
Reads the content from the file at 'Path' into the previously declared 'Content' variable.
Dim FileContent As String Read_File(FileContent, "story.txt") Draw_Text(Top_Screen, 1, 1, FileContent) 'Draws the contents of story.txt on the top screen at position 1, 1
Writes the 'Content' to the file at the 'Path'.
Dim Content As String = "Hello, World" Write_File(Content, "new_born.txt") 'Writes 'Hello World' to 'new_born.txt'
List_Files(Screen, X, Y, Path)
Lists files in the selected file system (see Switch_To_NitroFS() and Switch_To_FAT()). Default file system is NitroFS. Add files in 'Game Settings'.
Switches the file system commands to work with NitroFS (files contained within the NDS - See 'Game Settings' window).
Switches the file system commands to work with FAT (files stored alongside the NDS on the MicroSD card).
Enables the rotation of the specified instance. Most commonly, call it once in the 'Creation' event for the object. You can then set its angle with 'Set_Angle'.
Disables the rotation of the specified instance caused by Enable_Rotation or Set_Angle.
Sets the rotation angle for the specified instance. The angle is in Radians, and be sure to use Enable_Rotation first. To convert to and from Radians, see the below functions.
Converts a "human" angle (0-360) to Radians; commonly for use with Set_Angle.
Converts a Radian angle back to "human form" (0-360).
Angle_Between_Points(X1, Y1, X2, Y2)
Returns the angle between 2 points in Radians. You can use this with [X], [Y], Stylus.X, Stylus.Y to make objects face the stylus.
Distance_Between_Points(X1, Y1, X2, Y2)
Returns the distance between 2 points using Pythagoras. This is slow so use with care.