• 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!

one line toggle with function help?

S

Shadowblitz16

Guest
can someone help me understand why this is not working

Code:
image_frame = rround(2 - image_frame, 0, 2);
Code:
// description rround
// param var
// param min
// param max

var _var = argument[0] + 1;
var _min = argument[1];
var _max = argument[2];


return round((_var - _min) / (_max-_min)) * (_max - _min) + _min;
 
N

Never Mind

Guest
This post is kind of annoying. You don't explain what your trying to do.
I'm going to guess that anything your trying to accomplish with this script can be done by using a couple existing functions.

Real Number Functions
https://docs.yoyogames.com/source/dadiospice/002_reference/maths/real valued functions/index.html
Specifically:
round
clamp
abs
lerp
mean

If I'm totally off here and your script is doing something unique, then I apologize for giving a misinformed answer.. but I still think you should explain yourself if you want any real responses from people.
 
S

Shadowblitz16

Guest
I'm trying to make a value toggle between the two values which in this case are 0 and 2
this is so I can do something like..
Code:
if (state == 0)
    image_frame = rround(2 - image_frame, 0, 2);
else
    image_frame = rround(1 - image_frame, 0, 1);
this would toggle between 0 and 2 if the state is 0 otherwise it would toggle between 0 and 1
this function is here because if I just do something like..
Code:
image_frame = 2 - image_frame;
then it would fail if image_frame is not 0 or 2
 

TheouAegis

Member
Why not just do

if argument0 == argument1 argument0 = argument2
else argument0 = argument1;
return argument0;

?
 
S

Shadowblitz16

Guest
idk because I am dumb and I think outside the box
 
S

Shadowblitz16

Guest
ok I this doesn't work
I have a feeling it is because my button has 4 subimages..
-off up
-off down
-on up
-on down

this creates a problem when my button is toggled and the offsetted

this is my code
Code:
///////////////////////////////////////////////////
// Input
///////////////////////////////////////////////////

var _state  = mouse_check_state(mb_left);
var _region = mouse_check_region(input_rect[0], input_rect[1], input_rect[2], input_rect[3]);
var _input;
  
//Set input back to false if input is not of type toggle
if (input_type_ != 1) input = 0;

//Releasing
if (_state == 3)
{
    if (_region)
    {
        //Press type
        if (input_type_ == 0)
            image_frame = 0
        //Toggle type
        else if (input_type_ == 1)
            image_frame = toggle(image_frame, 0, 2) + 0;
      
        //Minimize
        if (minimizeable)
        {
            var _size = [0, max(rect[3] * minimized, minimized_height)]
            editor_set_element_image_size(self, _size[0], _size[1]);
            minimized = !minimized;
        }
    }
    else
    {
  
        image_frame = 0;
        input_state = 0;
        input = 0
    }
    dragging = 0;
    drag_x = 0;
    drag_y = 0;
}
//Holding
else if (_state == 2)
{
    if (_region)
    {
        if (input_type_ == 0)
            image_frame = 1;
        else if (input_type_ == 1)
            image_frame = toggle(image_frame, 0, 2) + 1;
    }
    else
    {
        if (!draggable)
            image_frame = 0;
        //input = 0 + (input_type_ == 2);
    }
  
    if (dragging)
    {
        editor_set_element_position(self, drag_x + mouse_x,  drag_y + mouse_y)
    }
}
//Clicked
else if (_state == 1)
{
    if (_region)
    {
        if (draggable)
        {
            dragging = 1;
            drag_x = image_rect[0] - mouse_x;
            drag_y = image_rect[1] - mouse_y;
        }
    }
}
Code:
/// @description toggle
/// @param val
/// @param a
/// @param b

var _val = argument[0];
var _a   = argument[1];
var _b   = argument[2];

if (_val == _b) _val = _a;
else _val = _b

return _val;
I don't really know a good way to do something like this where it toggles between two value and then get offsetted without breaking the toggle function

Edit: ok I think I got it I just made scripts to handle the button inputs separately so they are easier to read
 
Last edited by a moderator:
Top