ID:1979443
 
(See the best response by Popisfizzy.)
Code:
        SortItem()
src.client.screen-=items_list
var/xx=-128
var/yy=65
var/ct=0
var/start=0
if(c_page==1)
start=1
else
start=max(1,(c_page-1)) * re_item_max
var/end = min(start + re_item_max, items_list.len)
m_page=max(1,round(items_list.len/re_item_max))
var/deez=items_list.len%re_item_max
if(deez>0)
while(deez>=0)
deez-=re_item_max
m_page++
for(var/obj/J in items_list.Copy(start,min(items_list.len,end)))
J.screen_loc="CENTER:[xx],CENTER:[yy]"
J.layer=MOB_LAYER+11+EFFECTS_LAYER
src.client.screen+=J
xx+=32
ct++
if(ct==re_item_max)
break
if(ct==3)
yy-=32
xx=-128
ct=0


Problem description:
*IMPORTANT Note* Condition of replying to this post dictates : no lectures. If you're going to attempt to lecture me, please do yourself a favor-don't bother.

I don't need "pointers" on whats "more efficient" or queries about "why are you doing this" and

"WHAT ARE THOSE?"



It's time I won't spend to explain myself(counter productive) and you will just be ignored. Nothing personal.

Moving along-
This proc displays objects in an inventory on screen.

It seemed to be working fine up until a few days ago when I noticed this error:

runtime error: list index out of bounds
proc name: SortItem (/mob/Nin/proc/SortItem)
source file: Items.dm,66


I'm aware of what the error means, and how it should be fixed,I'm just pretty sure I've spent too much time in front of my PC and my brain is fried at the moment.

Line 66 refers to this line:
for(var/obj/J in items_list.Copy(start,min(items_list.len,end)))


Meaning it's not doing what I want it to do--which is only display items start through end.

Ex.
If I have 30 items in my inventory, and I only want to display 10 per page--
this would display the items appropriately, based on the players current page (c_page).


for(var/obj/J in items_list)


if not that then I'd grab and make a new list with the Copy there to loop through before using for() to check and see if it exists or something.
In response to Kozuma3
The items exist, I'm just trying to grab the correct end value, which is either the length of the list, or a full page *which is 9 items*.
Best response
Just do it based on the list index, rather than trying to cut out the right size of list. Not that it really matters in this particular case, but it'll be a bit more efficient anyways.
var
current_page = 5
page_size = 10

for(var/i = ((current_page-1) * page_size) + 1, (i <= (current_page * page_size) && (i <= Items.len), i ++)
DisplayItem(Items[i])
I'm not sure how this comment will be taken, but I do strongly feel as though the way you've done your scripting is overly complicated.

Since I've been needing to script myself one of these anyway, I decided to just build a new proc from the ground up. If I've understood your script entirely, this will do the same thing.

mob/proc/Display_Page()

if(items_list.len == 0)
return//No point in calculating an empty inventory

if(!client)
return//No client means no point in running

client.screen -= items_list//It would be better to iterate through your screen with something like for(var/obj/Items/o in client.screens), incase the list has been altered.

if(c_page < 1)
c_page = 1//Somehow backtracked

var/column = 3 //horizontal
var/row = 2//vertical

var/display_amount = row*column
var/start = (c_page-1) * display_amount

if(start > items_list.len)
c_page = round(items_list.len/display_amount)+ 1
start = (c_page-1) * display_amount

var/end = min(items_list.len,start+display_amount)

for(var/i=start+1;i<=end;i++)
var/spot = i - (1 + start)
var/xx = spot%column
spot -= xx
var/yy = spot/column
xx *= 32//Our spacing
yy *= -32

//If you have any offsets you'd like to use, just add them on.
//For instance, if I want all items slightly shifted to the left a little
//xx -= 32 //An offset

var/obj/J = items_list[i]//Normally you'd want to bounds_check, but we've pretty much done so already. As long as there's no delay, there should be no reason to bounds check
if(isobj(J))
J.screen_loc="CENTER:[xx],CENTER:[yy]"
J.layer=MOB_LAYER+11+EFFECTS_LAYER
src.client.screen+=J


I hope this helps in some way. I've tested it probably twenty times, and it all seems to work. (To be fair, this is basically the same thing Popisfizzy is suggesting. However, since I took the time to write it, I'm going to post, dang it).
In response to Ss4toby
@ssj4toby :

I don't think my way is overly complicated considering everything you just posted is probably about 2 x more coding than what I have at this point. Also a lot of the way that is set up is based on some help I got from Lummox a few months ago pertaining to this problem. No offense is taken but I also noticed some things about your code that personally I wouldn't do (which i think is the point of programming, its good to have preferences, styles and learn new things)

Personally:

It may seem overly complicated to you most likely because you may not have the full gist of what I'm accomplishing with it-curse of only seeing one piece of the puzzle.

If(!client)//doesn't always work. It's best to actually check with isnull (not sure why that is, maybe a DM quirk of some type)

Using a return in that way to force a break isn't really recommended either-you can never be sure what you're returning control to, so in general I try not to use those.

It actually isn't better to reiterate through the screen to remove the items in this instance, it's actually quicker(and simpler) to use the + or - , (Kaiochao taught me that as well a while back), especially since I'm paging through groups of items. I always remove the items_list before emptying it and selecting the next page to display, so there's no downside to using the short hands.

Looping would slow down the process. Copying is probably the fastest method altogether, since it just grabs only what I need from a pre established list and displays them.

Again this is all from personal experience and speed testing on my own as well. And your response is exactly why I asked people to refrain from taking the approach you did. You just sort of assumed you were better or more efficient-to my eyes, that's not the case, and the end result is that I ended up wasting my time having to explain myself-yet again..which, in my experience is a complete waste of my time (and yours) at this point.

@ Popisfizzy :
True, I was trying to get something similiar to what you have working, just couldn't get it to properly work, now I see that I was trying to set it up the wrong way.

I'll probably try incorporating that approach and seeing how it works out. Thanks.
In response to Avidanimefan
Avidanimefan wrote:
Using a return in that way to force a break isn't really recommended either-you can never be sure what you're returning control to, so in general I try not to use those.

What? returning a proc, or letting it fully execute does the same thing. Forcing it to end there is perfectly fine.

Again this is all from personal experience and speed testing on my own as well. And your response is exactly why I asked people to refrain from taking the approach you did. You just sort of assumed you were better or more efficient-to my eyes, that's not the case, and the end result is that I ended up wasting my time having to explain myself-yet again..which, in my experience is a complete waste of my time (and yours) at this point.

Saying "Look at my broken code and fix it without telling me why it's broken" is the same as saying "Make this system for me". We aren't here to make your game for you, we're here to help you understand why things are and aren't broken so you can learn. We're not trying to neigh-say your programming, you're better than most of the population of the Earth who can't code for their life, but you should be taking advice and not saying "ITS A WASTE OF TIME"
In response to Rushnut
I think you misunderstood- I don't expect anyone to make my games for me. Least of all someone with a blank profile, no noticable coding experience and therefore, no real valuable or worthwhile input to offer me in any way, shape or form.

Asking a question doesn't make you ignorant. Asking for a helping hand doesn't make you less deserving of respect.
Are you really that immature and simple minded?
Do you just enjoy sounding smart or do you actually use your brain?
You're a prime example of why this community is dwindling.
Self entitled, ignorant little pricks who- for the life of me-seem to think that everyone needs or wants to hear their misinformed opinions on any and everything, all the while they never actually contribute anything of value or substance.

Perhaps you should learn how to mind your own business, it will save you from getting roasted.
In response to Avidanimefan
Avidanimefan wrote:
I think you misunderstood- I don't expect anyone to make my games for me. Least of all someone with a blank profile, no noticable coding experience and therefore, no real valuable or worthwhile input to offer me in any way, shape or form.

Ayyy lmao. I won't even bother here, I don't think I have to, pretty sure you just know you're wrong.

Asking a question doesn't make you ignorant. Asking for a helping hand doesn't make you less deserving of respect.

You effectively said "This isn't working, fix it, and don't tell me how any of it could be better", when someone did tell you how to make it better, you were...

Are you really that immature and simple minded?
Do you just enjoy sounding smart or do you actually use your brain?
You're a prime example of why this community is dwindling.
Self entitled, ignorant little pricks

All of the above. Couldn't have put it better myself.

who- for the life of me-seem to think that everyone needs or wants to hear their misinformed opinions on any and everything, all the while they never actually contribute anything of value or substance.

When you posted in a forum asking for help, you kinda have to expect our opinions. And 90% of the people who post in this forum helping people, myself included, aren't misinformed, and are usually contributing things of value. Lol.

Perhaps you should learn how to mind your own business, it will save you from getting roasted.

Perhaps you should know what you're talking about.

I don't want to start a flame war, so I'll stop responding here. Feel free to give me your worst "roasting" that you can imagine, I'm sure I'll give it oh so much attention and care.
In response to Rushnut
It's one thing to call me wrong, but something completely different to call the moderators here wrong. You contradicted things Lummox, Kaiochao and several other people who are far better at what they do than yourself have instructed or said time and again.


The things I pointed out in particular are things that have been pointed out to me, directly-or indirectly- by reading posts here and there.

To be honest, I didn't come back and read this post for almost 4 days, because after a bit of rest,I fixed it myself as I usually do. (albeit-not as well as popisfizzy managed to).

There is no "flame war" I said my piece, plain and simple. Normally you wouldn't have even gotten that much attention I just have time on my hands because it's a lunch break.

Self important people often think what they want of themselves regardless of how the world views them or what actually is, so yea. I guess you have that going for you. + 1 for mental delusion.

My ramen is done. *thumbs up*
Everywhere you go causing chaos lol