slight optimization using if bools in a function
May 2, 2019 13:56:17 GMT
Post by donnaken15 on May 2, 2019 13:56:17 GMT
I've done this a handful of times with some things already but what could be a bit optimized in code is including a (==) bool check in a function rather than in an if statement. You could also multiply it if the statement returns as true like (10*(iscorrect)) An example could be something like (not any specific language but to demonstrate):
player_speed = getkey(key_right) * 5;
instead ofif (getkey(key_right)
player_speed = 5;
else
player_speed = 0;
ordraw_character(x, y, sprite, (player_walk)+(player_run*2)+(player_jump*3) <- (subimage)) (where 0 is the idle sprite) (1 is walking) (==1 with parentheses could be used too)
instead of maybeif (player_state == state_walking)
subimage = player_walk;
else if (player_state == state_run)
subimage = player_run;
else if (player_state == state_jump)
subimage = player_jump;
else
subimage = player_idle;
You could also do it with an increasing speed value like:
Here's real examples where I have done this:
(player_run*(hspeed>4))
Here's real examples where I have done this:
timeline_view_position -= mouse_wheel_up()*(timeline_view_position > -10) timeline_view_position += mouse_wheel_down()
draw_text(0,view_hview[0],string_copy("/!\ WARNING: LOW FRAMERATE",0,(fps<=room_speed/3)*26)
show_menu_ext(0,18,"1#New&Ctrl+N|2#Open&Ctrl+O|3#"+string_copy("!^",0,(active<=0)*2)+"Save&Ctrl+S|3#"+string_copy("!^",0,(active<=0)*2)+"Save as...&Ctrl+Shift+S|-|10#Options&Ctrl+U|4#Exit&Alt+F4",-1)
if mode_animation >= 0 && mode_animation < 720
hyper_scale=(1.75+(((mode<3)&&mode_animation<=720)*((
mode_animation*(mode_animation>=0))*-1+720)/720))
draw_set_color((c_white*!(beam>0))+
(c_bittrip_orange*(beam>0)*(mode>0))+
(c_white*(beam>0)*(mode==0)))
draw_set_alpha((.125+((7/8)*(beam>0)))*leftpressed)
draw_rectangle(room_width/2-8-549,room_height/2-8,
room_width/2+7-32,room_height/2+7,false)
draw_set_alpha((.125+((7/8)*(beam>0)))*rightpressed)
draw_rectangle(room_width/2-8+563,room_height/2-8,
room_width/2+24,room_height/2+7,false)
draw_set_alpha((.125+((7/8)*(beam>0)))*uppressed)
draw_rectangle(room_width/2-8,room_height/2-8-17,
room_width/2+7,room_height/2+7-307,false)
draw_set_alpha((.125+((7/8)*(beam>0)))*downpressed)
draw_rectangle(room_width/2-8,room_height/2-8+32,
room_width/2+7,room_height/2+7+295,false)
draw_set_alpha(1)