1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

Create random object from memory

Discussion in 'Programming' started by Pikr, Dec 3, 2019.

  1. Pikr

    Pikr Member

    Joined:
    Dec 3, 2019
    Posts:
    1
    Hi,
    first of all sorry about my bad english.
    What is my problem? In short. In the first room i will pick 30 random generated objects (from 60 random generated objects). Then i will go to the next room. I need to randomly generate 5 random objects from the list of 30 objects that i picked up in first room). I create i variable
    slovo1=""
    slovo2=""
    ..
    ..
    slovo30=""

    every time i pick up the object, it will write name of this object to the varialbe (slovo1 , slovo2). For now that is ok. At the end of the room, this variable will write to the memory variable
    m_slovo1 = slovo1
    m_slovo2 = slovo2
    and then set the slovo 1 - slovo 30 to "" (nothing).
    Now here is the problem. Everything is ok bud in the next room, it generates only 1 object again again and again.

    here is the code for first room
    if room = room_vl_1
    {
    pocet_chycenych_slov=0;
    ///poloha pri vytvoreni

    var n;
    n=0;
    n+=1; a[n]=obj_sl_1; //kazdy objekt se ulozi v poli *a* v poradi *n*
    n+=1; a[n]=obj_sl_2;
    n+=1; a[n]=obj_sl_3;
    n+=1; a[n]=obj_sl_4;
    n+=1; a[n]=obj_sl_5;
    n+=1; a[n]=obj_sl_6;
    n+=1; a[n]=obj_sl_7;
    n+=1; a[n]=obj_sl_8;
    n+=1; a[n]=obj_sl_9;
    n+=1; a[n]=obj_sl_10;
    n+=1; a[n]=obj_sl_11;
    n+=1; a[n]=obj_sl_12;
    n+=1; a[n]=obj_sl_13;
    n+=1; a[n]=obj_sl_14;
    n+=1; a[n]=obj_sl_15;
    n+=1; a[n]=obj_sl_16;
    n+=1; a[n]=obj_sl_17;
    n+=1; a[n]=obj_sl_18;
    n+=1; a[n]=obj_sl_19;
    n+=1; a[n]=obj_sl_20;
    n+=1; a[n]=obj_sl_21;
    n+=1; a[n]=obj_sl_23;
    n+=1; a[n]=obj_sl_24;
    n+=1; a[n]=obj_sl_25;
    n+=1; a[n]=obj_sl_26;
    n+=1; a[n]=obj_sl_27;
    n+=1; a[n]=obj_sl_28;
    n+=1; a[n]=obj_sl_29;
    n+=1; a[n]=obj_sl_30;
    n+=1; a[n]=obj_sl_31;
    n+=1; a[n]=obj_sl_32;
    n+=1; a[n]=obj_sl_33;
    n+=1; a[n]=obj_sl_34;
    n+=1; a[n]=obj_sl_35;
    n+=1; a[n]=obj_sl_36;
    n+=1; a[n]=obj_sl_37;
    n+=1; a[n]=obj_sl_38;
    n+=1; a[n]=obj_sl_39;
    n+=1; a[n]=obj_sl_40;
    n+=1; a[n]=obj_sl_41;
    n+=1; a[n]=obj_sl_42;
    n+=1; a[n]=obj_sl_43;
    n+=1; a[n]=obj_sl_44;
    n+=1; a[n]=obj_sl_45;
    n+=1; a[n]=obj_sl_46;
    n+=1; a[n]=obj_sl_47;
    n+=1; a[n]=obj_sl_48;
    n+=1; a[n]=obj_sl_49;
    n+=1; a[n]=obj_sl_50;
    n+=1; a[n]=obj_sl_51;
    n+=1; a[n]=obj_sl_52;
    n+=1; a[n]=obj_sl_53;
    n+=1; a[n]=obj_sl_54;
    n+=1; a[n]=obj_sl_55;
    n+=1; a[n]=obj_sl_56;
    n+=1; a[n]=obj_sl_57;
    n+=1; a[n]=obj_sl_58;
    n+=1; a[n]=obj_sl_59;
    n+=1; a[n]=obj_sl_60;
    n+=1; a[n]=obj_sl_61;
    n+=1; a[n]=obj_sl_62;
    n+=1; a[n]=obj_sl_63;
    n+=1; a[n]=obj_sl_64;
    n+=1; a[n]=obj_sl_64;



    //podmínka, aby se neopakovaly slova
    nahodny_objekt=a[irandom_range(1,n)]; //vybere se nahodne jeden z nich
    nahodny_objekt2=a[irandom_range(1,n)]; //vybere se nahodne jeden z nich
    nahodny_objekt3=a[irandom_range(1,n)];
    nahodny_objekt4=a[irandom_range(1,n)];
    nahodny_objekt5=a[irandom_range(1,n)];
    //podmínka na vzdálenost (pozici )
    with(instance_create(0,0,nahodny_objekt)) //vlozi se do mistnosti na pozici 0,0
    {
    x=irandom_range(112,864-sprite_width); //a ihned se premisti na pozici mezi hornim levym
    y=irandom_range(80,512-sprite_height); //a dolnim pravym koncem herniho pole
    move_snap(16,16); //zarovnani do mrizky by asi ani nebylo treba, slova jsou dost velka pro kolizi

    }

    with(instance_create(0,0,nahodny_objekt2)) //vlozi se do mistnosti na pozici 0,0
    {
    x=irandom_range(112,864-sprite_width); //a ihned se premisti na pozici mezi hornim levym
    y=irandom_range(80,512-sprite_height); //a dolnim pravym koncem herniho pole
    move_snap(16,16); //zarovnani do mrizky by asi ani nebylo treba, slova jsou dost velka pro kolizi
    }

    with(instance_create(0,0,nahodny_objekt3)) //vlozi se do mistnosti na pozici 0,0
    {
    x=irandom_range(112,864-sprite_width); //a ihned se premisti na pozici mezi hornim levym
    y=irandom_range(80,512-sprite_height); //a dolnim pravym koncem herniho pole
    move_snap(16,16); //zarovnani do mrizky by asi ani nebylo treba, slova jsou dost velka pro kolizi
    }

    with(instance_create(0,0,nahodny_objekt4)) //vlozi se do mistnosti na pozici 0,0
    {
    x=irandom_range(112,864-sprite_width); //a ihned se premisti na pozici mezi hornim levym
    y=irandom_range(80,512-sprite_height); //a dolnim pravym koncem herniho pole
    move_snap(16,16); //zarovnani do mrizky by asi ani nebylo treba, slova jsou dost velka pro kolizi
    }

    with(instance_create(0,0,nahodny_objekt5)) //vlozi se do mistnosti na pozici 0,0
    {
    x=irandom_range(112,864-sprite_width); //a ihned se premisti na pozici mezi hornim levym
    y=irandom_range(80,512-sprite_height); //a dolnim pravym koncem herniho pole
    move_snap(16,16); //zarovnani do mrizky by asi ani nebylo treba, slova jsou dost velka pro kolizi
    }
    }

    and for second room

    if room= room_lvl_2
    {
    pocet_chycenych_slov=0;
    ///poloha pri vytvoreni

    var n;
    n=0;
    n+=1; a[n]=sebrana_slova_nove.u_slovo1; //kazdy objekt se ulozi v poli *a* v poradi *n*
    n+=1; a[n]=sebrana_slova_nove.u_slovo2;
    n+=1; a[n]=sebrana_slova_nove.u_slovo3;
    n+=1; a[n]=sebrana_slova_nove.u_slovo4;
    n+=1; a[n]=sebrana_slova_nove.u_slovo5;
    n+=1; a[n]=sebrana_slova_nove.u_slovo6;
    n+=1; a[n]=sebrana_slova_nove.u_slovo7;
    n+=1; a[n]=sebrana_slova_nove.u_slovo8;
    n+=1; a[n]=sebrana_slova_nove.u_slovo9;
    n+=1; a[n]=sebrana_slova_nove.u_slovo10;
    n+=1; a[n]=sebrana_slova_nove.u_slovo11;
    n+=1; a[n]=sebrana_slova_nove.u_slovo12;
    n+=1; a[n]=sebrana_slova_nove.u_slovo13;
    n+=1; a[n]=sebrana_slova_nove.u_slovo14;
    n+=1; a[n]=sebrana_slova_nove.u_slovo15;
    n+=1; a[n]=sebrana_slova_nove.u_slovo16;
    n+=1; a[n]=sebrana_slova_nove.u_slovo17;
    n+=1; a[n]=sebrana_slova_nove.u_slovo18;
    n+=1; a[n]=sebrana_slova_nove.u_slovo19;
    n+=1; a[n]=sebrana_slova_nove.u_slovo20;
    n+=1; a[n]=sebrana_slova_nove.u_slovo21;
    n+=1; a[n]=sebrana_slova_nove.u_slovo22;
    n+=1; a[n]=sebrana_slova_nove.u_slovo23;
    n+=1; a[n]=sebrana_slova_nove.u_slovo24;
    n+=1; a[n]=sebrana_slova_nove.u_slovo25;
    n+=1; a[n]=sebrana_slova_nove.u_slovo26;
    n+=1; a[n]=sebrana_slova_nove.u_slovo27;
    n+=1; a[n]=sebrana_slova_nove.u_slovo28;
    n+=1; a[n]=sebrana_slova_nove.u_slovo29;
    n+=1; a[n]=sebrana_slova_nove.u_slovo30;




    //podmínka, aby se neopakovaly slova
    nahodny_objekt=a[irandom_range(1,n)]; //vybere se nahodne jeden z nich
    nahodny_objekt2=a[irandom_range(1,n)]; //vybere se nahodne jeden z nich
    nahodny_objekt3=a[irandom_range(1,n)];
    nahodny_objekt4=a[irandom_range(1,n)];
    nahodny_objekt5=a[irandom_range(1,n)];
    //podmínka na vzdálenost (pozici )
    with(instance_create(0,0,nahodny_objekt)) //vlozi se do mistnosti na pozici 0,0
    {
    x=irandom_range(112,864-sprite_width); //a ihned se premisti na pozici mezi hornim levym
    y=irandom_range(80,512-sprite_height); //a dolnim pravym koncem herniho pole
    move_snap(16,16); //zarovnani do mrizky by asi ani nebylo treba, slova jsou dost velka pro kolizi

    }

    with(instance_create(0,0,nahodny_objekt2)) //vlozi se do mistnosti na pozici 0,0
    {
    x=irandom_range(112,864-sprite_width); //a ihned se premisti na pozici mezi hornim levym
    y=irandom_range(80,512-sprite_height); //a dolnim pravym koncem herniho pole
    move_snap(16,16); //zarovnani do mrizky by asi ani nebylo treba, slova jsou dost velka pro kolizi
    }

    with(instance_create(0,0,nahodny_objekt3)) //vlozi se do mistnosti na pozici 0,0
    {
    x=irandom_range(112,864-sprite_width); //a ihned se premisti na pozici mezi hornim levym
    y=irandom_range(80,512-sprite_height); //a dolnim pravym koncem herniho pole
    move_snap(16,16); //zarovnani do mrizky by asi ani nebylo treba, slova jsou dost velka pro kolizi
    }

    with(instance_create(0,0,nahodny_objekt4)) //vlozi se do mistnosti na pozici 0,0
    {
    x=irandom_range(112,864-sprite_width); //a ihned se premisti na pozici mezi hornim levym
    y=irandom_range(80,512-sprite_height); //a dolnim pravym koncem herniho pole
    move_snap(16,16); //zarovnani do mrizky by asi ani nebylo treba, slova jsou dost velka pro kolizi
    }

    with(instance_create(0,0,nahodny_objekt5)) //vlozi se do mistnosti na pozici 0,0
    {
    x=irandom_range(112,864-sprite_width); //a ihned se premisti na pozici mezi hornim levym
    y=irandom_range(80,512-sprite_height); //a dolnim pravym koncem herniho pole
    move_snap(16,16); //zarovnani do mrizky by asi ani nebylo treba, slova jsou dost velka pro kolizi
    }
    }

    i know it is not very good option to do this but my friend need to finish this fast as a school project (she do not need good coding she need result .exe)

    thank you
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice