![]() |
![]() |
#1 |
Registered User
Join Date: Oct 2011
Location: UK
Age: 47
Posts: 304
|
return newtype item no. in Blitz
I'm trying to write a piece of blitz basic 2 code that will allow me to return the number of the currently used list item.
Say if I have a newtype variable path "bobs()\num" in a while/wend loop and I want to return the number of the current item in the list on a certain condition to enable passing it to other variables and act on it etc. I've somehow not been able to do this although it's never been a problem with normal arrays. I can access the individual items of the list using a subscript "bobs(var)\num" as a normal array, however I cannot find the means in blitz to return the (var) above which is currently being processed in a list. I've taken to changing all newtype variables into normal arrays - presenting it's own problems! I'm stuck with the above problem, any ideas? ![]() EDIT: To help clarify this I'll better explain the problem. In my main loop is a section dealing with a particular action enforced by the player onto other objects. The objects are part of a list, and the particular action is represented by another variable. I simply want to pass the number of the listed object in question to this variable. I have an idea that using a 'pointer' type variable could work, but it seems strange that it should be necessary given that the lists have pointers of their own already, and I can access them directly using the subscript number. code example: Code:
resetlist thislist() while nextitem thislist() if thislist()\condition =1 then thisvariable= thislist() wend ; same example using normal array for N=0 to ENDLIST if thisitem(N)=1 then thisvariable=N next N I'm not sure that I'm meant to do this with Blitz2 as it warns in the manual about using usual array indexing, for the most part however, it works - albeit missing the last part of the puzzle. ![]() Last edited by leathered; 19 March 2013 at 14:05. |
![]() |
![]() |
#2 |
Join Date: Jul 2008
Location: Sweden
Posts: 2,269
|
Maybe I'm misunderstanding you, but can't you just keep count manually, or are you looking for a more elegant solution?
Code:
n = 0 ResetList list() While NextItem(list()) If list()\cond = 1 Then index = n n+1 Wend |
![]() |
![]() |
#3 | |
Registered User
Join Date: Oct 2011
Location: UK
Age: 47
Posts: 304
|
Quote:
The problem appeared to be happening when items are removed from the list and then added again. The listed objects are enemy bobs for a game, and are currently removed from the list when 'killed' and added again when needed. Blitz does this quite elegantly, and for the most part works fine. However I've still found no way of accurately returning the number of the listed item. If 'index' above is a variable then the code you've suggested would work first time around but fall apart once the item has been killed and added again - the listed item number apparently does not match the number being counted. I think that under some circumstances it would, but in my case it doesn't; I'm not quite able to explain why... I think that in many circumstances it simply wouldn't matter as long as the fields were always being accessed in the same way, whereas I'm using a few methods depending on the situation. While typing this I remembered there was another section of code where I was doing something very similar to your suggestion. In the end the solution was simply to move the problem area outside of the 'loopy list' and count the items manually with another loop. (typed properly this time ![]() Code:
;GR counter for GRNUM=0 to nn if nast(GRNUM)\gr=>1 then bobs()\gr=nast(GRNUM)\gr:gbd=GRNUM next GRNUM ;initialise if INI=1 resetlist nast() while nextitem (nast()) nast()\etc1=etc ;and so on... Thankyou Leffmann and credit to you sir ![]() ![]() ps. I was very curious of your use of the word 'index'. I'd assumed you meant a variable. Assumption being what it is I tried it and found the 'index list' command. So I may have misunderstood you and perhaps there's a way of returning the 'currently used item' after all - I mean, there must be ![]() |
|
![]() |
![]() |
#4 |
Join Date: Jul 2008
Location: Sweden
Posts: 2,269
|
Yes I meant for "index" to just be an integer variable, but once you remove f.ex the 5th item from the list then the following item will be the new 5th and so on, so the index may be no good anymore.
PushItem and PopItem works for keeping track of an item directly, but it's a last-in-first-out stack and can be a bit inconvenient, but may work for what you're doing. |
![]() |
![]() |
#5 |
Registered User
Join Date: Oct 2011
Location: UK
Age: 47
Posts: 304
|
I'd thought that I was re-initialising the 'fake' index numbers with every 'new item' - but you're right and that would explain the difficulty. I've encountered trouble with blitz and the stack before, but was wondering if PushItem and PopItem would do the job as you've confirmed.
So there's a couple of new ways I can get the job done when it comes to optimising again. TBH I think I've been staring at a computer screen for too many late nights for too long. I've got a holiday coming up and thought I'd be de-bugging for the whole trip, but as it is I'll be doing some chilling (literally, in Scotland ![]() Thanks again Leffmann; your help is most appreciated ![]() |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
What is this Amiga Item? | Peter | support.Hardware | 9 | 29 July 2010 18:05 |
Possible collectors item? | CRAZG | Amiga scene | 1 | 28 May 2007 00:14 |
M&M3 item evaluator | Amigamancer | Retrogaming General Discussion | 4 | 04 April 2005 23:31 |
another ebay item that just cracked me up | sarek2k | MarketPlace | 17 | 15 March 2005 08:04 |
Here's a rare item! | th4t1guy | MarketPlace | 7 | 15 June 2004 11:03 |
|
|