Legacy GM [SOLVED] get_integer_async issue

A

Alan Régis

Guest
I'm building a custom dice roller in wich the number of sides of the dice is provided by user through a get_integer_assync function. Here's the code:

Code:
// In the Create Event

show_roll = false ;
dice_type = "" ;
Code:
// in the Mouse Left Press Event

dice_question = get_integer_async("How many sides?","");
Code:
// In the Async Dialog Event

dice_check = ds_map_find_value(async_load, "id");

if dice_check == dice_question
{
   if ds_map_find_value(async_load, "status")
      {
        if ds_map_find_value(async_load, "result") != ""
             {
                dice_type = ds_map_find_value(async_load, "result");
                script_execute(dice_roll) ;
             }
      
      }
}
This is the "dice_roll" script:
Code:
show_roll = true;
randomize() ;
dice_result = irandom_range(1,dice_type) ;
And Finally:
Code:
// In the Draw Event

draw_self() ;

pos_vertical = obj_chatbox.y + 15  ;
pos_horizontal = obj_chatbox.x + 25 ;

if show_roll
{ 
    draw_set_font(font_dados) ;
    draw_text(pos_horizontal, pos_vertical, "Rolled a d" + string(dice_type) + " and got a " + string(dice_result)) ;
}
Now the issue: Everything works as intended except for the result of the dice, wich always returns 1. something like this:

>(left click custom dice object)
>Opens Dialog "How many sides?"
>User insert a value, let's say 999
>This text shows on screen: "You rolled a d999 and got a 1"

Needless to say i tested it many times, so it's not a coincidence. It always returns 1.


What am i doing wrong? Can someone please help me?
(and sorry for the bad english.)
 
P

PWL

Guest
I'm quite sure you should call randomize() at the start of your game only:
Manual: Should you wish to test with true random, you should call this function at the start of your game.
What are your results if you get rid of randomize()? Do you keep getting 1 every time?
 
A

Alan Régis

Guest
I'm quite sure you should call randomize() at the start of your game only:

What are your results if you get rid of randomize()? Do you keep getting 1 every time?
I dont think that randomize() is the issue here. I believe that as long as randomize() is called before any "random function" it should work well.

The same "dice_roll script" is used for a regular dice object with a "dice_type" fixed value. So when i roll a regular d6 (dice_type = 6) it gives me random results as intended... The issue seems to be only with the custom dice.

(But yeah, i tested it with randomize() at a GameStart event instead of script and the same issue occour)

Maybe i'm doing something wrong in the Async event dialog? Can you spot something wrong there?

And thank you for your assistance! :)
 
P

PWL

Guest
The same "dice_roll script" is used for a regular dice object with a "dice_type" fixed value. So when i roll a regular d6 (dice_type = 6) it gives me random results as intended... The issue seems to be only with the custom dice.
That sounds like something goes wrong with the dice_type variable, however you draw it correctly afterwards. I mean, it shows what kind of dice was thrown so at the same time I'm not sure. Can you make sure the dice_type is set correctly before you throw the dice?
Code:
show_roll = true;
randomize() ;
show_message(dice_type); // Does this show you the correct value?
dice_result = irandom_range(1,dice_type) ;
 
A

Alan Régis

Guest
That sounds like something goes wrong with the dice_type variable, however you draw it correctly afterwards. I mean, it shows what kind of dice was thrown so at the same time I'm not sure.
That's exactly what is confusing me. The dice_type is working, as we can see from the "Rolled a 999d (dice type) and got a 1"
I have done the "show_message(dice_type)" verification and it does give me the right value, however, the dice_result variable still always returns 1. =/
 
P

PWL

Guest
Very strange behaviour. Try setting dice_type like this, with real() to make sure GM understands that it's a number and doesn't pass it as a string into irandom_range(). Maybe the ds_map with the async values keeps it as a string instead of a number, and then messes up your irandom_range().
Code:
dice_type = real(ds_map_find_value(async_load, "result"));
I also find it very strange that you initialize dice_type to be and empty string ("") when it is supposed to hold a number. Why isn't it set to a default of 1?
 
A

Alan Régis

Guest
Thats it! You were right. the async_load result was returning a string instead of a number.

dice_type = real(ds_map_find_value(async_load, "result")); solved the issue!

Thank you very much, PWL!
 
Top