Legacy GM [SOLVED] HELP please Code - Random objects

G

Guilherme Hernandez

Guest
I have found it difficult to find the respective codes for the actions of the DnD.
I've been working with DnD lately. But I'd like to know.

I would like to know the code, to create objects randomly but that are in the same position,
And the code for random objects around the room.

And I would like to know which programming language is used for the gamemaker.

If someone also knows some website that shows these codes, I would be grateful. : D

Thank you all for the attention.
 
K

Koohyar

Guest
Hi there.

The language of GameMaker is GML which is the GameMaker Language. This means that this language belongs to this software and you don't find it anywhere else. But it's pretty easy to learn.

As for the random object issue, what do you mean of random? Do you mean you like to make some objects "randomly through time" or you want to create objects having "random variables"?
 
G

Guilherme Hernandez

Guest
I do not know very well to differentiate, but the code that represents the DnD (Create instance of random object)
 
G

Guilherme Hernandez

Guest
instance_create(random(objSignal.x), random(objSignal.x), obj_fuel); << Like this, but this code, is it to a Random location right?
 
G

Guilherme Hernandez

Guest
Let me show you how my DnD is:

Create instance of random object
[
Object 1: objRed
Object 1: objBlue
Object 1: objYellow
Object 1: objGreen
x: objSignal.x
y: objSignal.y
]
But I need it in code.
 
T

Token Chingy

Guest
1. Assuming you have the following 5 object defined in your resource tree: "object1", "object2", "object3", "object4", "object5". We can use the following code in a controller object to randomly generate 1 of the 5 object instances repeatedly in the same position. This is a never ending loop... you'll need to modify it to your requirements.
Code:
// Create Event.
generate = true;
xCord = 64;
yCord = 64;

// Step Event.
while (generate == true) {
    randomObject = random_range(1, 5);

    switch (randomObject) {
        case 1:
            instance_create(object1, xCord, yCord);
            break;
        case 2:
            instance_create(object2, xCord, yCord);
            break;
        case 3:
            instance_create(object3, xCord, yCord);
            break;
        case 4:
            instance_create(object4, xCord, yCord);
            break;
        case 5:
            instance_create(object5, xCord, yCord);
            break;
    }
}
2. Now you can do something similar for generating an object instance at random positions. Assuming you have the object "object1" defined in your resource tree:
Code:
// Create Event.
generate = true;
xCord = 64;
yCord = 64;

// Step Event.
while (generate == true) {
    xCord = random_range(0, room_width);
    yCord = random_range(0, room_height);
    instance_create(object1, xCord, yCord);
}
3. Game Maker uses the Game Maker Language (Shortened to GML).

4. You can look at the Game Maker Studio Documentation for more information about the functions for Game Maker Studio as well as look at the tutorials Game Maker Studio provides. I won't link them, you have access to this forum, the YYG website and Google.
 
Last edited by a moderator:

chamaeleon

Member
instance_create(random(objSignal.x), random(objSignal.x), obj_fuel); << Like this, but this code, is it to a Random location right?
random() will give you a value between 0 and objSignal.x. If objSignal.x is 0, you will get a very non-random result, equal to zero every time. Is objSignal.x supposed to represent the maximum possible value random() should return?
 
T

Token Chingy

Guest
So you need to create one of the four colour-named objects at the location indicated by objSignal's current x and y position?
Code:
instance_create(objSignal.x, objSignal.y, choose(objRed, objBlue, objYellow, objGreen));
Oh that's cool! There's a function called "choose()"? That's neat. Gosh it's been a while since I've touched GML.
 
G

Guilherme Hernandez

Guest
This is what i mean, Thanks you @NightFrost .

But thank you from the heart, to everyone who tried to help. I ask for forgiveness those who have tried because can not respond to each one, because I am in the middle of work. But as I said, thank you all !!
 
K

Koohyar

Guest
As a side note, if you only want to change the color of the object, it's not necessary to have different objects for different colors. You can simply add sub-images to the sprite of "one" object and then change the image_index of the sprite of that object accordingly.

If you are pretty new to the concept of GML, it is better to start following tutorials BEFORE any attempt to make your original game. After doing a bunch of tutorials you'll feel comfortable in applying your ideas to your projects.

Good Luck! :)
 
Top