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

Anyway to do this?

Jihl

Member
Hey there all!

I am trying to make an X*2 long array which has pairs of numbers, the first the item id and second the item quantity, I'm doing this with a switch statement but it looks horribly unefficient and an unproffesional piece of code </3

I need to get the array in once piece so I can pass it as an argument to the final script. But I havent figured out how to do it iteratively.

Any ideas on how to make this iterative?
Code:
var total_slots = buffer_read(buffer, buffer_u8)
 
// Create auxiliar list and array
var list_aux = ds_list_create()
var array_aux = 0
 
for (var i = 0; i < total_slots; i++)
{
   // Add item to the list
   ds_list_add(list_aux, buffer_read(buffer, buffer_u16))
  
   // Add item quantity to the list
   ds_list_add(list_aux, buffer_read(buffer, buffer_u16))
}

// Make array to pass as argument
switch total_items
{
    case 1:
        array_aux = array(list_aux[0], list_aux[1])
        break
     
    case 2:
        array_aux = array(list_aux[0], list_aux[1], list_aux[2], list_aux[3])
        break

   case 3: ...
   case 4: ....
}

// Show the corpse loot "You don't need to know where does the corpse variable comes from for this post"
with corpse scr_show_loot_ensured(total_slots, array_aux)
Thank you very much! :D
 
Last edited:

Kyon

Member
Look into "for" statements.
Like,
Code:
for (i=0; i<4; i+=1;){
list_aux[i]=0;
}
which made 4 array variables.
Change that "4" to another variable, like max items, or amount of items you have at the moment or idk, not sure what you're trying to do.
But that "for" statement will help you.
 

Jihl

Member
Look into "for" statements.
Like,
Code:
for (i=0; i<4; i+=1;){
list_aux[i]=0;
}
which made 4 array variables.
Change that "4" to another variable, like max items, or amount of items you have at the moment or idk, not sure what you're trying to do.
But that "for" statement will help you.
I get that the for statement can iterate through the list, but can I use a for statement inside an argument for a function?

It would look like this:
Code:
array_aux = array( for(....))
I am pretty sure that this can't be done X_X I need to get the array in just once piece, and the only way of calling the function "array(arg0, arg1, ...)" is to call it from that switch statement, otherwise you would create lots of different arrays.

Thanks for your reply! :D
 
Last edited:

Jihl

Member
I was so mistaken, you were right, arrays can be made that way. This question was nonsense!

I changed the code for this, in any case anyone was wondering
Code:
// Create auxiliar array
var array_aux
  
for (var i = 0; i < total_slots; i+=2)
{
   // Add item to the array
   array_aux[i] = buffer_read(buffer, buffer_u16)
   // Add item quantity to the array
   array_aux[i+1] = buffer_read(buffer, buffer_u16)
}
  
with corpse scr_show_loot_ensured(total_slots, array_aux)
 
Last edited:

Gamebot

Member
EDIT: Just saw last post I was partially correct.

Are buffers necessary? Not that its bad. Are you trying to randomize the loot too?

Go with maps to hold the loot name and value.

Use a list to add and randomize by name. Pick one from the list. Now you can call the map key by that pick and get the value.
 
Last edited:

Jihl

Member
EDIT: Just saw last post I was partially correct.

Are buffers necessary? Not that its bad. Are you trying to randomize the loot too?

Go with maps to hold the loot name and value.

Use a list to add and randomize by name. Pick one from the list. Now you can call the map key by that pick and get the value.
Yes, buffers are neccesary. The function is called from the client project when you touch a corpse and the server's got the information. So I have to read the loot information and keep it updated in case another person grabs some of the loot (like in tibia)
 
Top