Draw item stats in the right position

B

Brrrzzz

Guest
Hello everyone!

Im working on a game with items, that have random generated stats.
I want these stats to be shown whenever the player hovers the mouse above the item. They also should be drawn on the right place.

I currently working with

//stat 1
if (stat_1 = 0 && !armor = 0){stat_1 = armor}
if (stat_1 = 0 && !dmg = 0){stat_1 = dmg}
if (stat_1 = 0 && !magic = 0){stat_1 = magic}
if (stat_1 = 0 && !hp = 0){stat_1 = hp}
if (stat_1 = 0 && !mp = 0){stat_1 = mp}
if (stat_1 = 0 && !mp_regain = 0){stat_1 = mp_regain}
if (stat_1 = 0 && !endurance = 0){stat_1 = endurance}
if (stat_1 = 0 && !endurance_reg = 0){stat_1 = endurance-reg}
if (stat_1 = 0 && !runspd = 0){stat_1 = runspd}
if (stat_1 = 0 && !balance = 0){stat_1 = balance}
if (stat_1 = 0 && !shield_block = 0){stat_1 = shield_block}
if (stat_1 = 0 && !shield_reg = 0){stat_1 = shield_reg}
//stat 2
if (stat_2 = 0 && !stat_1 = armor && !armor = 0){stat_2 = armor}
if (stat_2 = 0 && !stat_1 = dmg && !dmg = 0){stat_2 = dmg}
if (stat_2 = 0 && !stat_1 = magic && !magic = 0){stat_2 = magic}
if (stat_2 = 0 && !stat_1 = hp && !hp = 0){stat_2 = hp}
if (stat_2 = 0 && !stat_1 = mp && !mp = 0){stat_2 = mp}
if (stat_2 = 0 && !stat_1 = mp_regain && !mp_regain = 0){stat_2 = mp_regain}
if (stat_2 = 0 && !stat_1 = endurance && !endurance = 0){stat_2 = endurance}
if (stat_2 = 0 && !stat_1 = endurance_reg && !endurance_reg = 0){stat_2 = endurance-reg}
if (stat_2 = 0 && !stat_1 = runspd && !runspd = 0){stat_2 = runspd}
if (stat_2 = 0 && !stat_1 = balance && !balance = 0){stat_2 = balance}
if (stat_2 = 0 && !stat_1 = shield_block && !shield_block = 0){stat_2 = shield_block}
if (stat_2 = 0 && !stat_1 = shield_reg && !shield_reg = 0){stat_2 = shield_reg}

and so on...stat_1/stat_2/stat_3 etc. are the stats, that are then drawn on the screen.

But that obviously doesnt work for more stats, cause that would get incredibly long.
Is there a better/cleverer way to look through the stats and mark them as "taken" so stat_2/stat_3 etc. would not take them as stat, when stat_1 already took it?

Thank you for your time.
 
B

Brrrzzz

Guest
and how exactly could that work?

I tryd

///set stats to an array
stats[1] = 0
stats[2] = 0
stats[3] = 0
stats[4] = 0
stats[5] = 0

stat[1] = dmg
stat[2] = magic
stat[3] = hp
stat[4] = mp
stat[5] = mp_regain
stat[6] = endurance
stat[7] = endurance_reg
stat[8] = runspd
stat[9] = armor
stat[10] = balance
stat[11] = shield_block
stat[12] = shield_reg

///and the try to find the right stat
edit : somehow the forum deletes my [ ] + s

for (s = 1; s < 12; s++){
if (stat >= 1){
stats = stat
}
}

doesnt work at all...But im also pretty bad with loops.
 

wamingo

Member
Edit: the first code I gave was terrible.. sorry. This is better... but maybe still not what you need. Need more details for better answer.
Code:
//create

// item 1
Stats[0,0] = armor
Stats[0,1] = hp
// etc...

// item 2
Stats[1,0] = armor
Stats[1,1] = hp
// etc...

Text = 0;
SelectedItem=0;   // you have to change this at runtime
ShowText = false;

//step

ShowText=false;
// mouse over code here!
{
    ShowText=true;
    for (var i=0; i<array_length_2d(Stats,SelectedItem); i++){
        if (Stats[SelectedItem,i]>=0){
            Text[k++] = Stats[SelectedItem,i];
            if (k>=3) break;
        }
    }
}


// draw

if (ShowText){
    for (var i=0; i<3; i++)
        draw_text(x, y+i*10, Text[i]);
}
 
Last edited:
B

Brrrzzz

Guest
Code:
var k=0, stats=3, text=0;
for (var i=0; i<stats; i++){
    if (stats[i]>=0){
        text[k]=stats[i];
        k++;
    }
}
here 'text' array will hold up to 3 values of stats
Thanks, but it still just draws "0" in every text slot...

if (distance_to_point(mouse_x, mouse_y) <= 0){
draw_text(x,y,text[0])
draw_text(x,y+10,text[1])
draw_text(x,y+20,text[2])
}

Is that the right?
 

wamingo

Member
Is that the right?
My code was terrible, and I edited it. But you really need to offer more details on what object you're mousing over and how you store your stats and such. Do you have a controller? More details needed for better answer.
 
H

Humphrey M

Guest
As they said above you should try using arrays and for loops. For the original code though, shouldn't you be using == instead of = in if statements?
 
H

Humphrey M

Guest
GM accepts both.
I find using == helps understand that you're doing a conditional, plus it's the standard in most other languages.
My bad, I'm still adapting to gml from javascript lol
 
Top