• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Help again in coding!

P

prithvidiamond

Guest
(Seriously, I am noob at this language)
Hello everyone,
Once again I have a problem in GML,
You can go over the code below:

Within Create event:
globalvar fruitguess0;

globalvar fruitguess1;

globalvar fruitguess2;

globalvar fruitguess3;

randomize();

fruitguess0 = irandom_range(0,3);

fruitguess1 = irandom_range(0,3);

fruitguess2 = irandom_range(0,3);

fruitguess3 = irandom_range(0,3);

Within Draw event:

i
f fruitguess0 = 0
{
draw_self();
draw_sprite(spr_fr_wm,0,560,830);
}


if fruitguess0 = 1
{
draw_self();
draw_sprite(spr_fr_ap,0,560,830);
}

if fruitguess0 = 2
{
draw_self();
draw_sprite(spr_fr_sb,0,560,830);
}

if fruitguess0 = 3
{
draw_self();
draw_sprite(spr_fr_rs,0,560,830);
}

if fruitguess1 = 0
{
draw_self();
draw_sprite(spr_fr_wm,0,400,830);
}


if fruitguess1 = 1
{
draw_self();
draw_sprite(spr_fr_ap,0,400,830);
}

if fruitguess1 = 2
{
draw_self();
draw_sprite(spr_fr_sb,0,400,830);
}

if fruitguess1 = 3
{
draw_self();
draw_sprite(spr_fr_rs,0,400,830);
}

if fruitguess2 = 0
{
draw_self();
draw_sprite(spr_fr_wm,0,240,830);
}


if fruitguess2 = 1
{
draw_self();
draw_sprite(spr_fr_ap,0,240,830);
}

if fruitguess2 = 2
{
draw_self();
draw_sprite(spr_fr_sb,0,240,830);
}

if fruitguess2 = 3
{
draw_self();
draw_sprite(spr_fr_rs,0,240,830);
}

if fruitguess3 = 0
{
draw_self();
draw_sprite(spr_fr_wm,0,80,830);
}


if fruitguess3 = 1
{
draw_self();
draw_sprite(spr_fr_ap,0,80,830);
}

if fruitguess3 = 2
{
draw_self();
draw_sprite(spr_fr_sb,0,80,830);
}

if fruitguess3 = 3
{
draw_self();
draw_sprite(spr_fr_rs,0,80,830);
}

The problem is that I don't know how to declare in GML that:

fruitguess0, fruitguess1, fruitguess2 and fruitguess3 can NEVER BE EQUAL TO EACH OTHER.

It would be really appreciated if anyone can help me on this problem.

All answers are accepted!

Thank you,

prithvidiamond
 
J

jirrev

Guest
That particular problem can be solved by doing the following:

Code:
var list, i;

list = ds_list_create();
for(i = 0; i < 4; i++)
{
ds_list_add(list, i);
}
randomize();
ds_list_shuffle(list);
fruitguess1 = list[| 0]
fruitguess2 = list[| 1]
fruitguess3 = list[| 2]
fruitguess4 = list[| 3]

ds_list_delete(list);
Put this in the create event and it should work

if you need any more help you can just send me a PM, I'm always willing to help some more.
 
P

prithvidiamond

Guest
That particular problem can be solved by doing the following:

Code:
var list, i;

list = ds_list_create();
for(i = 0; i < 4; i++)
{
ds_list_add(list, i);
}
randomize();
ds_list_shuffle(list);
fruitguess1 = list[| 0]
fruitguess2 = list[| 1]
fruitguess3 = list[| 2]
fruitguess4 = list[| 3]

ds_list_delete(list);
Put this in the create event and it should work

if you need any more help you can just send me a PM, I'm always willing to help some more.

I will surely check if this works and let you know,
Thanks, I had posted a thread even the day before yesterday and the community had so many replys,
The community is great!

Thanks again,

prithvidiamond
 
F

faissaloo

Guest
There's a much faster way, use an array for fruitguess and then assign values to them randomly by using a seed and xor:
Code:
globalvar fruitguess;
fruitguess[0]=0
fruitguess[1]=0
fruitguess[2]=0
fruitguess[3]=0
var i;
var seed;
seed=irandom(3)
for (i=0;i<=3;i++)
{
    fruitguess[i]=i^seed
}
Haven't tested it but it should work.
 
L

Life is code

Guest
You could try this. After you randomize fruitguess0 and then fruitguess1 check with a if statement if there are the same and if there are randomize then loop back to just before fruitguess1 was randomize.
So the code would look like this sort of.
Randomize()
Fruitguess0 = irandom_range(0,3)
Loop1()
Fruitguess1 = iranfom_range(0,3)
If(fruitguess1 = fruitguess0){
Goto loop1()
}

Then just use the same code to check the rest. BTW the code is probs wrong as i am doing this on a phone, its just there to help you understand
 
J

jirrev

Guest
There's a much faster way, use an array for fruitguess and then assign values to them randomly by using a seed and xor:
Code:
globalvar fruitguess;
fruitguess[0]=0
fruitguess[1]=0
fruitguess[2]=0
fruitguess[3]=0
var i;
var seed;
seed=irandom(3)
for (i=0;i<=3;i++)
{
    fruitguess[i]=i^seed
}
Haven't tested it but it should work.
It's true that's much better, and normally I'd choose that too but the other functions in the step-event would have to be changed as well (which would have my prefference to be fair).
Nevertheless I'd say it's smarter to stick with your guns before revamping all of your project
 
F

faissaloo

Guest
It's true that's much better, and normally I'd choose that too but the other functions in the step-event would have to be changed as well (which would have my prefference to be fair).
Nevertheless I'd say it's smarter to stick with your guns before revamping all of your project
I highly disagree, it's best to tackle these now while the project is in earlier stages so op isn't left with something unmaintainable and unscalable, it prevents headache and wasted time in the long run.
 
P

prithvidiamond

Guest
I highly disagree, it's best to tackle these now while the project is in earlier stages so op isn't left with something unmaintainable and unscalable, it prevents headache and wasted time in the long run.
The code I sent on top is just a part of the code, so ya method is really fast to make changes with. None the less, I also appreciate jirrev's idea as well!

prithvidiamond
 
J

jirrev

Guest
I highly disagree, it's best to tackle these now while the project is in earlier stages so op isn't left with something unmaintainable and unscalable, it prevents headache and wasted time in the long run.
Again, I agree, but I don't think Arrays are things you casually pick up without knowing what to do with them. If prithvidiamond knows what Arrays do and how they function I'm more than happy to write a functional script in the step event, but seeing how he's still using loose sprites per state and no sub-images I highly doubt arrays are feasable.

if you want to try using Arrays just give a shout and I'll write something down for you.

Yours truly,
Jirrev
 
P

prithvidiamond

Guest
Again, I agree, but I don't think Arrays are things you casually pick up without knowing what to do with them. If prithvidiamond knows what Arrays do and how they function I'm more than happy to write a functional script in the step event, but seeing how he's still using loose sprites per state and no sub-images I highly doubt arrays are feasable.

if you want to try using Arrays just give a shout and I'll write something down for you.

Yours truly,
Jirrev
I really like your way of logic and I agree. As I stated before (Seriously, I am noob at this language), I only know about some array_length_1d (I don't even know that is right). Any way's it seem that his method is working but I have made changes to only one-forth of my code (its LONG!!!!!!!), so it will take me a lot time to see if it really works.

prithvidiamond.
 
C

CoderJoe

Guest
To help learn GML take a look at the documentation included (under help menu). Also, when in the code editor if you press ctrl+middle click (i think) it open the documentation for that specific thing. To learn GML I basically read the entire documentation :p
 
Top