Lord Valarian Posted July 20, 2012 Share Posted July 20, 2012 Copy all the references of the container to an array. Then sort it based on an element in the reference(like actorvalue). All three types of arrays won't do this. How? array_var temp1 ;array construct: all three typesLet temp1[NumItems] := InvObj ;doesn't work. Link to comment Share on other sites More sharing options...
QQuix Posted July 20, 2012 Share Posted July 20, 2012 You need to give more detail of the actual code, for example:1. What is the value of the variable NumItems?2. And InvObj?3 How are you initializing the array? (I suppose ";array construct: all three types" is just a comment)4. What do you mean by "does not work"? Link to comment Share on other sites More sharing options...
Lord Valarian Posted July 21, 2012 Author Share Posted July 21, 2012 (edited) You need to give more detail of the actual code, for example:1. What is the value of the variable NumItems?2. And InvObj?3 How are you initializing the array? (I suppose ";array construct: all three types" is just a comment)4. What do you mean by "does not work"? It will crash oblivion without printing anything. This is greatly simplified code. If you can tell me how to get this to work, I will be able to use the concepts in my code. array_var InvRefs short NumInvItems short tc ref pInvObj ref pCont Begin OnActivate Set pCont to GetActionRef ;get access to players inv Set NumInvItems to 0 Let InvRefs := ar_Construct Array ; the other types dont work either. foreach pInvObj <- pCont Let InvRefs[NumInvItems] := pInvObj Set NumInvItems to (NumInvItems + 1) loop set tc to 0 while (tc <= NumInvItems) Let pInvObj := InvRefs[tc] printc "Item: %n" pInvObj Set tc to (tc + 1) loop End Once I have the array, I need to sort the references by one stat in them. Edited July 21, 2012 by Lord Valarian Link to comment Share on other sites More sharing options...
Maskar Posted July 21, 2012 Share Posted July 21, 2012 I think your array is going out of bounds when checking while (tc <= NumInvItems). If you have 1 item in your inventory you'll check both [0] and [1]. However, [1] doesn't exist. You might want to try < rather than <=. Link to comment Share on other sites More sharing options...
QQuix Posted July 21, 2012 Share Posted July 21, 2012 What Maskar says and . . . When used to iterate over an inventory or container, ForEach returns "Inventory References". Inventory References are temporary references that give the script access to several inventory attributes not accessible by other means (e.g. the health of an item in inventory). But temporary references are only valid in that iteration through the loop. The next iteration the same ref refers to a different item and when you exit the loop, the ref becomes invalid. Therefore, inventory references should never be stored, as they cease to exist rather quickly. Your game crashes at "Let pInvObj := InvRefs[tc]", because, at that point in the script, InvRefs[tc] contains 'null'. The array, itself, is fine, btw. For more details, check the Inventory References in the OBSE doc. For your purpose, check the WIKI article on Walking Through Inventory Items Link to comment Share on other sites More sharing options...
Lord Valarian Posted July 21, 2012 Author Share Posted July 21, 2012 I already have many cs wiki pages and the obse manual. Here's another way which should work. Arrays must support this type of code. I'll assume i'm doing something wrong. Without being able to do this, i'll have to trash the whole addition. "can't eval expression" I might have one more way array_var InvRefs short InvIndex ref pInvObj ref pCont Begin OnActivate set pCont to GetActionRef ;get access to player's inv Let InvRefs := ar_Construct Array Let InvIndex := 0 foreach pInvObj <- pCont Let InvIndex:= InvIndex + 1 Let InvRefs[invIndex] := InvIndex loop ; now that loop has terminated, pInvObj has been set to null (0) End Link to comment Share on other sites More sharing options...
QQuix Posted July 21, 2012 Share Posted July 21, 2012 No. Same as Maskar pointed out before: you are increasing the counter before using it, so the first time "Let InvRefs[invIndex] := InvIndex" is executed, InvIndex will be 1, and that will give you an error because Array type arrays must start with index 0. Also, you are not using pInvObj within the loop. What exactly are you planning to do with the player items? Link to comment Share on other sites More sharing options...
Lord Valarian Posted July 22, 2012 Author Share Posted July 22, 2012 array_var InvRefs short InvIndex ref pInvObj ref pCont Begin OnActivate set pCont to GetActionRef ;get access to player's inv Let InvRefs := ar_Construct Array Let InvIndex := -1 foreach pInvObj <- pCont Let InvIndex:= InvIndex + 1 Let InvRefs[invIndex] := InvIndex ;An expression failed to evaluate to a valid result loop ; now that loop has terminated, pInvObj has been set to null (0) End Same error. You'll have to wait until the mod comes out. ;) All I need is this concept to work. I'll cross-post this on the obse comments. Link to comment Share on other sites More sharing options...
QQuix Posted July 22, 2012 Share Posted July 22, 2012 This code of yours works fine, so the problem must be on the code you are not showing.Without knowing where you want to go, I can't help you getting there.Good luck. Link to comment Share on other sites More sharing options...
Lord Valarian Posted July 26, 2012 Author Share Posted July 26, 2012 short health ; obse code set health to 71 printc "health: %g%%" temp ; temp= current health/max health health: 71 Percents won't print. Also, I created a sample full script using this. I'll repost it later. I had to remove all arrays from my code. I tried a completely different way of doing it. Once I did, the code worked. :) Thanks for the assist. Link to comment Share on other sites More sharing options...
Recommended Posts