Whats the worst code you have written

Discussion in 'Off Topic' started by fxokz, Nov 17, 2016.

  1. fxokz

    fxokz Member

    Joined:
    Jul 3, 2016
    Posts:
    450
    When i look back at this page i actually cringe a little because of how badly its written.

    Code:
    ///UPGRADES!!!
    
    //turret 1
    if player_money >= selected_turret.upgrade_cost && selected_turret = obj_turret1 && current_turret.times_upgraded = 0 //if not upgraded at all
    {
        current_turret.fire_rate -= 5;
        current_turret.radius += 5;
        current_turret.damage += 5;
        current_turret.image_index += 1;
        current_turret.times_upgraded +=1;
        player_money -= selected_turret.upgrade_cost;
    } else if player_money >= selected_turret.upgrade_cost && selected_turret = obj_turret1 && current_turret.times_upgraded = 1 //if upgraded once
    {
        current_turret.fire_rate -= 10;
        current_turret.radius +=5;
        current_turret.damage +=10;
        current_turret.image_index += 1;
        current_turret.times_upgraded +=1;
        player_money -= selected_turret.upgrade_cost;
    }
    
    //turret 2
    if player_money >= selected_turret.upgrade_cost && selected_turret = obj_turret2 && current_turret.times_upgraded = 0 //if not upgraded at all
    {
        current_turret.fire_rate -= 2;
        current_turret.radius += 5;
        current_turret.damage += 3;
        current_turret.image_index += 1;
        current_turret.times_upgraded +=1;
        player_money -= selected_turret.upgrade_cost;
    } else if player_money >= selected_turret.upgrade_cost && selected_turret = obj_turret2 && current_turret.times_upgraded = 1 //if upgraded once
    {
        current_turret.fire_rate -= 3;
        current_turret.radius +=7;
        current_turret.damage +=6;
        current_turret.image_index += 1;
        current_turret.times_upgraded +=1;
        player_money -= selected_turret.upgrade_cost;
    }
    
    //turret 3
    if player_money >= selected_turret.upgrade_cost && selected_turret = obj_turret3 && current_turret.times_upgraded = 0 //if not upgraded at all
    {
      //current_turret.fire_rate -= .1; TOO OP
        current_turret.radius += 5;
        current_turret.damage += 2;
        current_turret.image_index += 1;
        current_turret.times_upgraded +=1;
        player_money -= selected_turret.upgrade_cost;
    } else if player_money >= selected_turret.upgrade_cost && selected_turret = obj_turret3 && current_turret.times_upgraded = 1 //if upgraded once
    {
        current_turret.fire_rate -= .1;
        current_turret.radius +=10;
        current_turret.damage +=3;
        current_turret.image_index += 1;
        current_turret.times_upgraded +=1;
        player_money -= selected_turret.upgrade_cost;
    }
    
    //turret 4
    if player_money >= selected_turret.upgrade_cost && selected_turret = obj_turret4 && current_turret.times_upgraded = 0 //if not upgraded at all
    {
        current_turret.fire_rate -= 5;
        current_turret.radius += 2;
        current_turret.damage += 10;
        current_turret.image_index += 1;
        current_turret.times_upgraded +=1;
        player_money -= selected_turret.upgrade_cost;
    } else if player_money >= selected_turret.upgrade_cost && selected_turret = obj_turret4 && current_turret.times_upgraded = 1 //if upgraded once
    {
        current_turret.fire_rate -= 5;
        current_turret.radius += 3;
        current_turret.damage += 10;
        current_turret.image_index += 1;
        current_turret.times_upgraded +=1;
        player_money -= selected_turret.upgrade_cost;
    }
    
    //turret 5
    if player_money >= selected_turret.upgrade_cost && selected_turret = obj_turret5 && current_turret.times_upgraded = 0 //if not upgraded at all
    {
      //current_turret.fire_rate -= 3;
        current_turret.radius += 3;
        current_turret.damage += 5;
        current_turret.image_index += 1;
        current_turret.times_upgraded +=1;
        player_money -= selected_turret.upgrade_cost;
    } else if player_money >= selected_turret.upgrade_cost && selected_turret = obj_turret5 && current_turret.times_upgraded = 1 //if upgraded once
    {
        current_turret.fire_rate -= 5;
        current_turret.radius +=4;
        current_turret.damage +=5;
        current_turret.image_index += 1;
        current_turret.times_upgraded +=1;
        player_money -= selected_turret.upgrade_cost;
    }
    
    
    
    
    

    I hope i never go through the pain of that ever again. What about you guys? real curious.
     
  2. When I first started with GM, I had no idea how parenting worked. I thought for every object you made (like a ground or wall object), you needed a separate collision code for each one. So I basically had this:
    Code:
     //obj_ground
        if (place_meeting(x+hsp_final,y,obj_ground))
    {
        while(!place_meeting(x+sign(hsp_final),y,obj_ground))
        {
            x += sign(hsp_final);
        }
            hsp_final=0;
            hsp = 0;
    }
    
    over and over for each new ground object I made. So...yeah...
     
    fxokz likes this.
  3. Cantavanda

    Cantavanda 〜Flower Prince〜

    Joined:
    Jun 23, 2016
    Posts:
    74
    Code:
    //create event
    instance_destroy(self)
    It really doesn't do anything
     
    fxokz likes this.
  4. Maximus

    Maximus Guest

    Code:
    ///scr_add(a,b)
    {
        var a = argument0;
        var b = argument1;
        return a + b;
    }
    
    Code:
    for (var i = 9; i > -1; i++)
    {
        // wow, this loop is taking forever
    }
    
     
    Rivo, Dark, Nocturne and 5 others like this.
  5. ASR

    ASR Member

    Joined:
    Jul 24, 2016
    Posts:
    8
    [deleted]
     
    Last edited: Jul 28, 2019
    fxokz likes this.
  6. RujiK

    RujiK Member

    Joined:
    Jun 21, 2016
    Posts:
    178
    When I first began modding, I wanted to do use a simple command called "Lock" to lock a car's doors. Correct Usage: MyCar lock true;

    But I used "Lock MyCar" because that made more sense grammatically and got this error:
    Error and: Type Null, expected bool

    This was my journey to success:
    Code:
    MyCar Lock bool
    MyCar Lock expected bool
    MyCar Lock TorF (True or false)
    Lock MyCar bool
    bool Lock MyCar
    expected bool Lock MyCar
    Lock bool MyCar
    etc. 
    When I finally got it working I felt so smart that I had programmed an entire single command. Ahh, good memories.
     
    Nocturne, fxokz and Kahvana like this.
  7. roytheshort

    roytheshort The Village Idiot

    Joined:
    Jun 20, 2016
    Posts:
    72
    Code:
    if(fps < 60) then {
         fps = -60;
    }
    
    Thought I would change the past ;-;
     
  8. RujiK

    RujiK Member

    Joined:
    Jun 21, 2016
    Posts:
    178
    @KingdomOfGamez
    That actually works in GMS2, you just need to disable read only varaibles.


    Here is an old game I made with some rubbish code that runs really slow:
    [​IMG]

    Now I just put this in the begin-step event every frame: fps += 9999;

    And viola!
    [​IMG]
    (I've had this gif's sitting around for over a month)
     
    udcyorks, KingdomOfGamez and Kahvana like this.
  9. Ninety

    Ninety Member

    Joined:
    Jun 21, 2016
    Posts:
    244
    Frankly it'd be quicker to list the code I've written well.
     
  10. I am perfect.
     
  11. Maximus

    Maximus Guest

    Code:
    if instance_exists(object_index)
    {
        instance_create(x,y,object_index);
    }
    
     
  12. Changgi

    Changgi Member

    Joined:
    Oct 20, 2016
    Posts:
    45
    10 food_produce()
    20 goto (10)

    I wanted to freeze the room once without using Sleep because it caused problems with other parts of the game so I wanted to make the fps = 0 but GM told me that that wasn't possible. Then I thought it was probably the case because if the fps=0 then it wouldn't actually perform the next step, so the program would be stuck there forever.
     
    KingdomOfGamez likes this.
  13. Mercerenies

    Mercerenies Member

    Joined:
    Jun 21, 2016
    Posts:
    131
    Here.
    [​IMG]
    Yes, that's code. It's written in an esolang called Piet, and it was a monster to write.
     
  14. BattleRifle BR55

    BattleRifle BR55 Member

    Joined:
    Jun 24, 2016
    Posts:
    1,017
    Code:
    var1 = abs(var2) * sign(var2);
     
    Gradius and KingdomOfGamez like this.
  15. Hyomoto

    Hyomoto Member

    Joined:
    Jul 7, 2016
    Posts:
    1,080
    The worst code I've written will be the code I write today. All code you write will look idiotic one day, because when you look back on it with all the experience you've gained, you'll wonder why you ever thought it was a good idea to do it that way in the first place. Here's some code I was proud of in the past:
    Code:
    if transitionSpeed > 0 {
        transition += 1;
      
        transitionProgress = bias( 0.3, transition / transitionSpeed );
    
        x = lerp( transStartX, transEndX, transitionProgress );
        y = lerp( transStartY, transEndY, transitionProgress );
        width  = lerp( transStartWidth, transEndWidth, transitionProgress );
        height = lerp( transStartHeight, transEndHeight, transitionProgress );
      
        if transition == transitionSpeed { transitionSpeed = 0; transition = 0 }
      
    }
    Man, I thought it was so smart! Here's what that code looks like today:
    Code:
    if transition != undefined {
        var _data, _data, _transition;
      
        if is_array( transition ) {
            _transition = transitions[ transition[ 0 ] ];
          
            if array_length_1d( transition ) == 3 { transitionSpeed = [ 0, transition[ 2 ] ] }
            else { transitionSpeed = [ 0, _transition[ 0 ] ] }
          
            transitionWait    = transition[ 1 ];
          
        } else {
            _transition = transitions[ transition ];
            transitionSpeed    = [ 0, _transition[ 0 ] ];
            transitionWait    = 0;
          
        }
        transitionData = [ ];
      
        for ( var _i = 1; _i < array_length_1d( _transition ); _i++ ) {
            var _data = _transition[ _i ], _I = _i - 1;
            switch( _data[ 0 ] ) {
                case transition_x :
                    transitionData[ _I, 1 ] = ( _data[ 1 ] == undefined ) ? x : ( _data[ 1 ] );
                    transitionData[ _I, 2 ] = ( _data[ 2 ] == undefined ) ? x : ( _data[ 2 ] );
                    break;
              
                case transition_y :
                    transitionData[ _I, 1 ] = ( _data[ 1 ] == undefined ) ? y : ( _data[ 1 ] );
                    transitionData[ _I, 2 ] = ( _data[ 2 ] == undefined ) ? y : ( _data[ 2 ] );
                    break;
                  
                case transition_width :
                    transitionData[ _I, 1 ] = ( _data[ 1 ] == undefined ) ? ( width ) : ( _data[ 1 ] );
                    transitionData[ _I, 2 ] = ( _data[ 2 ] == undefined ) ? ( width ) : ( _data[ 2 ] );
                    break;
                  
                case transition_height :
                    transitionData[ _I, 1 ] = ( _data[ 1 ] == undefined ) ? ( height ) : ( _data[ 1 ] );
                    transitionData[ _I, 2 ] = ( _data[ 2 ] == undefined ) ? ( height ) : ( _data[ 2 ] );
                    break;
                  
                case transition_rotate :
                    transitionData[ _I, 1 ] = ( _data[ 1 ] == undefined ) ? rotate : _data[ 1 ];
                    transitionData[ _I, 2 ] = ( _data[ 2 ] == undefined ) ? rotate : _data[ 2 ];
                    break;
                  
                case transition_alpha :
                    transitionData[ _I, 1 ] = ( _data[ 1 ] == undefined ) ? alpha : _data[ 1 ];
                    transitionData[ _I, 2 ] = ( _data[ 2 ] == undefined ) ? alpha : _data[ 2 ];
                    break;
                  
                case transition_scale :
                    transitionData[ _I, 1 ] = ( _data[ 1 ] == undefined ) ? scale : _data[ 1 ];
                    transitionData[ _I, 2 ] = ( _data[ 2 ] == undefined ) ? scale : _data[ 2 ];
                    break;
          
            }
            transitionData[ _I, 0 ] = _data[ 0 ];
          
        }
        transition = undefined;
      
    }
    if transitionSpeed != undefined && transitionWait == 0 {
        var _progress = ++transitionSpeed[ 0 ] / transitionSpeed[ 1 ];
      
        for ( var _i = 0; _i < array_height_2d( transitionData ); _i++ ) {
            switch( transitionData[ _i, 0 ] ) {
                case transition_x :
                    x = lerp( transitionData[ _i, 1 ], transitionData[ _i, 2 ], _progress );
                    break;
              
                case transition_y :
                    y = lerp( transitionData[ _i, 1 ], transitionData[ _i, 2 ], _progress );
                    break;
                  
                case transition_width :
                    width = lerp( transitionData[ _i, 1 ], transitionData[ _i, 2 ], _progress );
                    break;
                  
                case transition_height :
                    height = lerp( transitionData[ _i, 1 ], transitionData[ _i, 2 ], _progress );
                    break;
                  
                case transition_rotate :
                    rotate = lerp( transitionData[ _i, 1 ], transitionData[ _i, 2 ], _progress );
                    break;
                  
                case transition_alpha :
                    alpha = lerp( transitionData[ _i, 1 ], transitionData[ _i, 2 ], _progress );
                    break;
                  
                case transition_scale :
                    scale = lerp( transitionData[ _i, 1 ], transitionData[ _i, 2 ], _progress );
                    break;
                  
            }
          
        }
        transitionProgress    = _progress;
      
        if _progress = 1 { transitionSpeed = undefined }
      
    } else { transitionWait -= 1 }
    
    One day I'll look back at this and punch myself. Seemed like a good idea at the time, and it worked: next task!
     
  16. Wraithious

    Wraithious Member

    Joined:
    Jun 24, 2016
    Posts:
    1,165
    you mean code that worked? haha this was my "global cave system" i made first learning to code in gamemaker 3.3
    //straight across//
    {if global.cave=0 || global.cave=4 || global.cave=20 || global.cave=40
    || global.cave=67 || global.cave=115 || global.cave=81 || global.cave=86
    || global.cave=1 || global.cave=5 || global.cave=10 || global.cave=11
    || global.cave=14 || global.cave=15 || global.cave=34 || global.cave=37
    || global.cave=70 || global.cave=48 || global.cave=7 || global.cave=36
    || global.cave=9 || global.cave=61 || global.cave=63 || global.cave=74
    || global.cave=29 || global.cave=60 || global.cave=92 || global.cave=100
    || global.cave=9 || global.cave=13 || global.cave=75 || global.cave=95
    || global.cave=26 || global.cave=60 || global.cave=82 || global.cave= 91
    || global.cave=67 || global.cave=91 || global.cave=69 || global.cave=88
    || global.cave=103 || global.cave=118 || global.cave=123 || global.cave=146
    || global.cave=119 || global.cave=121 || global.cave=122 || global.cave=124
    || global.cave=127 || global.cave=128 || global.cave=130 || global.cave=131
    || global.cave=133 || global.cave=135 || global.cave=140 || global.cave=144
    || global.cave=148 || global.cave=154 || global.cave=157 || global.cave=158
    || global.cave=160 || global.cave=161 || global.cave=164 || global.cave=165
    || global.cave=172 || global.cave=178 || global.cave=181 || global.cave=182
    || global.cave=33 || global.cave=97 || global.cave=120 || global.cave=189
    || global.cave=193 || global.cave=194 || global.cave=196 || global.cave=197
    || global.cave=198 || global.cave=200 image_index=1;
    //up and down//
    if global.cave=79 || global.cave=84 || global.cave=72 || global.cave=102
    || global.cave=2 || global.cave=101 || global.cave=93 || global.cave=89
    || global.cave=12 || global.cave=16 || global.cave=65 || global.cave=87
    || global.cave=106 || global.cave=3 || global.cave=17 || global.cave=99
    || global.cave=39 || global.cave=66 || global.cave=21 || global.cave=30
    || global.cave=58 || global.cave=62 || global.cave=78 || global.cave=105
    || global.cave=73 || global.cave=76 || global.cave=90 || global.cave=6
    || global.cave=8 || global.cave=2 || global.cave=22 || global.cave=23
    || global.cave=24 || global.cave=32 || global.cave=43 || global.cave=44
    || global.cave=45 || global.cave=46 || global.cave=47 || global.cave=50
    || global.cave=52 || global.cave=54 || global.cave=56 || global.cave=76
    || global.cave=83 || global.cave=104 || global.cave=35 || global.cave=38
    || global.cave=107 || global.cave=108 || global.cave=109 || global.cave=111
    || global.cave=112 || global.cave=113 || global.cave=114 || global.cave=94
    || global.cave=125 || global.cave=129 || global.cave=132 || global.cave=176
    || global.cave=134 || global.cave=139 || global.cave=141 || global.cave=163
    || global.cave=162 || global.cave=159 || global.cave=156 || global.cave=170
    || global.cave=185 || global.cave=179 || global.cave=180 || global.cave=183
    || global.cave=188 || global.cave=190 || global.cave=191 || global.cave=192
    || global.cave=195 || global.cave=199 || global.cave=201 image_index=0;
    //specials//
    //cave53 hidden room special//
    if self.y <310 && global.cave=110 && room=53 image_index=0;
    if self.y >250 && global.cave=110 && room=53 image_index=1;
    //T63 view1//
    if global.cave=42 || global.cave=96 || global.cave=49 || global.cave=145 && self.y <310
    && room=63 image_index=0;
    if global.cave=42 || global.cave=96 || global.cave=49 || global.cave=145 && self.y >310
    && room=63 image_index=1;
    //view2//
    if global.cave=166 || global.cave=168 || global.cave=171 || global.cave=174 && self.x <30
    && room=63 image_index=0;
    if global.cave=166 || global.cave=168 || global.cave=171 || global.cave=174 && self.x >30
    && room=63 image_index=1;
    //special//
    if global.cave=171 && self.x>200 image_index=0;
    //T64 view2//
    if global.cave=25 || global.cave=59 || global.cave=142 || global.cave=150 && self.y < 210
    image_index=0;
    if global.cave=25 || global.cave=59 || global.cave=142 || global.cave=150 && self.y > 210
    image_index=1;
    //T65 view1//
    if global.cave=18 || global.cave=19 && self.y < 10 image_index=1;
    if global.cave=18 || global.cave=19 && self.y > 10 image_index=0;
    //T65 view2//
    if global.cave=31 || global.cave=51 || global.cave=53 || global.cave=55
    || global.cave=80 && self.y < 10 && room=65 image_index=1;
    if global.cave=31 || global.cave=51 || global.cave=53 || global.cave=55
    || global.cave=80 && self.y > 10 && room=65 image_index=0;
    //T66 view1//
    if global.cave=149 || global.cave=152 || global.cave=68 && self.y < 310 && room=66 image_index=0;
    if global.cave=149 || global.cave=152 || global.cave=68 && self.y > 310 && room=66 image_index=1;
    //view2//
    if global.cave=71 && self.x < 310 && room=66 image_index=1;
    if global.cave=71 && self.x > 310 && room=66 image_index=0;


    }
    }
     
    Qarak and Nocturne like this.
  17. Cloaked Games

    Cloaked Games Member

    Joined:
    Jul 4, 2016
    Posts:
    824
    Anyone? :p This just goes on and on and on... Everything was drag and drop on this project except like, 2 things.

    bandicam 0195.jpg
     
    tserek and Nocturne like this.
  18. Cloaked Games

    Cloaked Games Member

    Joined:
    Jul 4, 2016
    Posts:
    824
    Wow. I literally just did this, like 5 minutes ago.

    Code:
    if (selected == false)
     {
     draw_text(x+12, y+8, string(value));
     }
    else if (selected == true)
     {
     draw_text(x+12, y-8, string(value));
     }
     
    SyntheticStorm9 likes this.
  19. tserek

    tserek Guest

    if a !=a
    {
    game_end();
    }

    that game would run long time? less serious..
    a = a+1; ... a +=1;
    a = a+a; ... a +=a;
     
    Last edited by a moderator: Dec 12, 2016
  20. grixm

    grixm Guest

    I have some really long and ugly expressions some places:

    Code:
    if ((mouse_x > 550) or (mouse_y > 550)) and (placing_status != 2) or (!ds_list_empty(semaster_list) and (
    ((mouse_x == clamp(mouse_x,rectxmin-2,rectxmax+2)) and (mouse_y == clamp(mouse_y,rectymin-2,rectymax+2)))
    or ((mouse_x == clamp(mouse_x,anchorx/$ffff*512-10,anchorx/$ffff*512+10)) and (mouse_y == clamp(mouse_y,anchory/$ffff*512-10,anchory/$ffff*512+10)))
    or ((mouse_x == clamp(mouse_x,rectxmin-20,rectxmin-2)) and (mouse_y == clamp(mouse_y,rectymax+2,rectymax+20)))
    or ((mouse_x == clamp(mouse_x,rectxmax+2,rectxmax+20)) and (mouse_y == clamp(mouse_y,rectymax+2,rectymax+20)))
    ))
        {
        //do stuff
        }
    
    Or this one before I learned of accessors which would have at least halved its size:
    Code:
    bezier_coeffs(ds_list_find_value(bez_list,0),ds_list_find_value(bez_list,1),ds_list_find_value(bez_list,2),ds_list_find_value(bez_list,3),ds_list_find_value(bez_list,4),ds_list_find_value(bez_list,5),ds_list_find_value(bez_list,6),ds_list_find_value(bez_list,7));
    
     
  21. nacho_chicken

    nacho_chicken Member

    Joined:
    Jun 21, 2016
    Posts:
    450
    Code:
    global.fnt_font_main = font_add_sprite(spr_font_main, ord(" "), true, 1);
    In the step event. It leaked memory, but not fast enough for me to catch it. It would take up like 1GB of RAM after an hour or so.
     
    csanyk likes this.
  22. Gradius

    Gradius Member

    Joined:
    Jun 21, 2016
    Posts:
    73
    I think you programmed an existential crisis into that an object. o_O
     
    Maximus and SyntheticStorm9 like this.
  23. Druid TC

    Druid TC Yellow Dog

    Joined:
    Jun 20, 2016
    Posts:
    40
    When I first downloaded GM I didn't faff around with the manual or anything, I just dived straight in and tried to make a remake of Bowmaster (which was the big thing among my friends at the time). I didn't understand the concept of variables, so instead I would create an object called 'canshoot' or something, and would create it in the corner of the room. When you fired an arrow, the canshoot object would be destroyed, and then created again thirty seconds thereafter. Problem was, you could see the little red square floating in the corner of the screen. I got around this by immediately setting the object's horizontal speed to 1000, so it would fly off the screen before you could see it!
     
    Ninety likes this.
  24. Dark

    Dark Member

    Joined:
    Jun 20, 2016
    Posts:
    43
    Variable hell.
    Code:
    ///sprite_draw_9patch(9patch list,sprite,subimg,x,y,w,h,color,alpha)
    /* Draws a sprite with 9patch, sugin a data returned from sprite_get_9patch.
     * Written by darkwalker247
     */
    var sp,sub,col,alp,ow,oh,nl,bx,by,bw,bh,sx,sy,sw,sh,cx,cy,cw,ch,sxs,sys,x1,y1,x2,y2,x3,y3,x4,y4,x5,y5,x6,y6,x7,y7,x8,y8,x9,y9;
    
    
    sp=argument1
    sub=argument2
    col=argument7
    alp=argument8
    ow=sprite_get_width(sp)-2
    oh=sprite_get_height(sp)-2
    nl=argument0
    bx=argument3-(sprite_get_xoffset(argument1))*(argument5/(ow))
    by=argument4-(sprite_get_yoffset(argument1))*(argument6/(ow))
    bw=argument5
    bh=argument6
    sx=ds_list_find_value(nl,0)+1
    sy=ds_list_find_value(nl,1)+1
    sw=ds_list_find_value(nl,2)
    sh=ds_list_find_value(nl,3)
    cx=ds_list_find_value(nl,4)
    cy=ds_list_find_value(nl,5)
    cw=ds_list_find_value(nl,6)
    ch=ds_list_find_value(nl,7)
    sxw=bw-(sx+(ow-(sx+sw)))
    syh=bh-(sy+(oh-(sy+sh)))
    sxs=sxw/sw
    sys=syh/sh
    x1=bx
    y1=by
    x2=bx+sx
    y2=by
    x3=x2+sxw
    y3=by
    x4=x3
    y4=by+sy
    x5=x3
    y5=y4+syh
    x6=x2
    y6=y5
    x7=bx
    y7=y5
    x8=bx
    y8=y4
    x9=bx+sx
    y9=by+sy
    
    draw_sprite_part_ext(sp,sub,1,1,sx,sy,x1,y1,1,1,col,alp) //1
    draw_sprite_part_ext(sp,sub,sx,1,sw,sy,x2,y2,sxs,1,col,alp) //2
    draw_sprite_part_ext(sp,sub,sx+sw,1,(ow+1)-(sx+sw),sy,x3,y3,1,1,col,alp) //3
    draw_sprite_part_ext(sp,sub,sx+sw,sy,(ow+1)-(sx+sw),sh,x4,y4,1,sys,col,alp) //4
    draw_sprite_part_ext(sp,sub,sx+sw,sy+sh,(ow+1)-(sx+sw),(oh+1)-(sy+sh),x5,y5,1,1,col,alp) //5
    draw_sprite_part_ext(sp,sub,sx,sy+sh,sw,(oh+1)-(sy+sh),x6,y6,sxs,1,col,alp) //6
    draw_sprite_part_ext(sp,sub,1,sy+sh,sx,(oh+1)-(sy+sh),x7,y7,1,1,col,alp) //7
    draw_sprite_part_ext(sp,sub,1,sy,sx,sh,x8,y8,1,sys,col,alp) //8
    draw_sprite_part_ext(sp,sub,sx,sy,sw,sh,x9,y9,sxs,sys,col,alp) //9
     
  25. Cloaked Games

    Cloaked Games Member

    Joined:
    Jul 4, 2016
    Posts:
    824
    You just made me cry, I'm not even kidding. This is sickening.
     
    fxokz and Guest User like this.
  26. nacho_chicken

    nacho_chicken Member

    Joined:
    Jun 21, 2016
    Posts:
    450
    Wow, it physically pained me to read that. I don't know whether to congratulate you or pray for your soul.
     
    Cloaked Games likes this.
  27. csanyk

    csanyk Member

    Joined:
    Jun 20, 2016
    Posts:
    821
    When I was working on my game Alamogordo for Ludum Dare 29, I wanted to replicate the font used by the Atari 2600 in the game E.T.

    I had not heard of sprite fonts before, and had never used them. So I improvised my own system. First, I fired up E.T. in an emulator and took screen captures of the score, taking care to get all 10 digits that I would need. I then cut out the numbers and put them into a sprite resource. As I recall, I had problems with the selection size not always being the same, or being exactly centered, so it took quite a bit of time just to get the sprite set up so that it was the right size for all digits, and all the digits were positioned the same relative to the sprite origin.

    Next, I wrote a script that took a number that I passed into it, converted that number into a string, then took each digit in the string and ran it through a switch statement, matching the value in the substring against a case that drew the right sub-image of my sprite that held the images of all the digits, and correctly offset them from one another, to draw the score on the screen. Only... no, I didn't even do it like that! I actually used div to get the ones, tens, hundreds, and thousands digit, and then used that value as the subimage index to draw the sprite.

    It worked beautifully, and at the time I thought it was brilliantly clever, but that there had to be a better way if only I had the time to RTFM.

    I was using the variable name "finds" for storing the score because the player's score goes up whenever they uncover something as they dig through the Alomogordo landfill, finding it, and you got a certain amount of points for each find you discovered.

    Code:
    Create Event:
    finds = 0;
    image_index = 0;
    image_speed = 0;
    
    ones_digit = 0;
    tens_digit = 0;
    hundreds_digit = 0;
    thousands_digit = 0;
    
    Draw Event: 
    ones_digit = finds mod 10;
    tens_digit = finds div 10;
    hundreds_digit = finds div 100;
    thousands_digit = finds div 1000;
    
    draw_sprite(sprite_index, ones_digit, x, y);
    draw_sprite(sprite_index, tens_digit, x-sprite_width, y);
    draw_sprite(sprite_index, hundreds_digit, x-(2*sprite_width), y);
    draw_sprite(sprite_index, thousands_digit, x-(3*sprite_width), y);
    
    At the time, my inspiration for the game was very last minute, I hadn't even intended to produce a project that weekend, but the idea came to me Sunday and I ended up putting the game together in literally about 10 hours altogether. So I was just pleased that it worked on the first try. I had literally no time to experiment or read through the manual in the hopes that I would find a proper way to do it!
     
  28. Hyomoto

    Hyomoto Member

    Joined:
    Jul 7, 2016
    Posts:
    1,080
    Nah, I did that recently for the GM2 beta simply because it didn't have the sprite add font availability. It's nice that it's there, preferred even, but what's important is it worked for you and did what you wanted. That's good code.
     
    nacho_chicken likes this.
  29. Schwee

    Schwee Member

    Joined:
    Jul 6, 2016
    Posts:
    171
    I won't post the code but I had a whole stair system setup using multiple bools for different inclines, along with dozens of conditionals checking different speeds and slopes. Reduces over 100 lines by just using a while loop to auto adjust height if the difference is within 1 pixel.
     
  30. csanyk

    csanyk Member

    Joined:
    Jun 20, 2016
    Posts:
    821
    Hmm, I wasn't aware that sprite fonts aren't in GMS2... (yet, I hope?) They are useful.
     
  31. fxokz

    fxokz Member

    Joined:
    Jul 3, 2016
    Posts:
    450
    How the absolute F can you keep up with all of those vars ahahah
     
    Dark likes this.
  32. Hyomoto

    Hyomoto Member

    Joined:
    Jul 7, 2016
    Posts:
    1,080
    They are now as part of the desktop beta, but the trial beta did not. However, my way of dealing with it was a bit different. I just stored strings as numbers in an array. Basically I did the conversion when the string was set, rather than when it was drawn, so I only had to do it once and I could just call draw_sprite directly. Generally calculations are, for whatever reason, slower during the draw event so it's often faster to cache your results during a step event.
     
    csanyk likes this.
  33. Joe

    Joe Guest

    Code:
    global.filename +=1
    game_save(string(global.filename))
    in the step.......
     
    Yanevski and Ninety like this.
  34. Ninety

    Ninety Member

    Joined:
    Jun 21, 2016
    Posts:
    244
    the ultimate quicksave
     
    Joe likes this.
  35. RujiK

    RujiK Member

    Joined:
    Jun 21, 2016
    Posts:
    178
    @Ninety @Joe

    Actually, saving the game every frame isn't that weird.

    How do you think overwatch, COD, and CS:GO have a replay function? They literally make a mini-savegame every frame.
     
  36. Dark

    Dark Member

    Joined:
    Jun 20, 2016
    Posts:
    43
    Considering that GM saves are almost like a savestate that's a terrible idea with a big game.
     
  37. Changgi

    Changgi Member

    Joined:
    Oct 20, 2016
    Posts:
    45
    Then that's no code, thus it isn't a bad code.
     
  38. Changgi

    Changgi Member

    Joined:
    Oct 20, 2016
    Posts:
    45
    I found out that GM8 at least requires the object holding the variable to be present in the room during the save in order for a local variable to be saved.
     
  39. Yanevski

    Yanevski Member

    Joined:
    Dec 18, 2016
    Posts:
    9
    I'd like to put this quote right here:
    Similarly a program that produces no results at all is infinitely slower than a badly written program which does.
     
  40. Tsa05

    Tsa05 Member

    Joined:
    Jun 21, 2016
    Posts:
    560
    Back in my chatbot-programming days I used to use the following code pretty often:
    execute_string()

    shudder
     
  41. JackTurbo

    JackTurbo Member

    Joined:
    Oct 19, 2016
    Posts:
    828
    Been working on a turn based strategy on and off for a while and recently took another look at my prototype GUI code.

    Dont have the code to hand but basically when it was a unit's turn it would display a portrait of the character in the bottom corner of the screen.

    What made the code so bad is that it would just keep drawing the image every frame and when it was the next units turn it would just draw them on top too, without ever destroying any thing.

    So by like 2 mins or so into a battle there would be a stack of around 10,000 of the same 3 or 4 images drawn on top of each other.
     
  42. gitwalrus

    gitwalrus Member

    Joined:
    Jun 24, 2016
    Posts:
    20
    Not GML but I work as a C programmer for embedded devices. I can't remember exactly what I did but I messed up the code and any control panel that had the new code downloaded to it would immediately become a brick and cease to start or do anything at all. Locked up like three control panels trying to fix this.
     
  43. David Richard

    David Richard Member

    Joined:
    Jun 20, 2016
    Posts:
    194
    My very first Visual Basic 6 project. to be sure to catch any errors in a function, I had put an "on error resume next" before every single line of code inside the same function. Horrible, HORRIBLE piece of code, sigh....:confused:
     
  44. Ethanicus

    Ethanicus Ethan L!

    Joined:
    Jun 26, 2016
    Posts:
    230
    I would show you some code on my character in Dreamer, but I don't think I can pinpoint ONE awful bit. I'd have to upload the whole thing. I started years ago and never realized how atrocious it all is until recently.
     

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