QBJS Swimming fish with Kelp - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1) +--- Forum: QBJS, BAM, and Other BASICs (https://qb64phoenix.com/forum/forumdisplay.php?fid=50) +--- Thread: QBJS Swimming fish with Kelp (/showthread.php?tid=1905) |
QBJS Swimming fish with Kelp - bplus - 08-15-2023 @dbox once again I am stumped trying to get this going on QBJS Code: (Select All) 'Option _Explicit RE: QBJS Swimming fish with Kelp - dbox - 08-15-2023 Hey @bplus, It looks like the same issue that you have found with at least one other example. The current version of QBJS doesn't support the new QB64 way of defining variables (e.g. As Integer LFish) inside custom type definitions yet. I'll put it on the list for the next release. I was able to get this working by just flattening out the fish Type definition: RE: QBJS Swimming fish with Kelp - bplus - 08-15-2023 Good! Thanks but what happened to the Kelp? RE: QBJS Swimming fish with Kelp - dbox - 08-15-2023 Oh, there it is: RE: QBJS Swimming fish with Kelp - bplus - 08-15-2023 That's it! I tried flattening the ReDim Shared Kelp() array but for some reason that didn't work. Maybe I forgot the first change with Type??? @dbox Is that all you changed to see Kelp? Or was there something else in subroutines? Sorry if this is pestering you but I'd like to share this on other forums like Aurel's or Friends where not all folks have or even think they like QB64. RE: QBJS Swimming fish with Kelp - dbox - 08-15-2023 Not pestering at all @bplus, happy to help! What I changed to get the kelp working was to add a call to Fix() to force some of those values to integers when accessing or setting array values. QBJS is a bit more flexible with values that can be passed to arrays. So, it doesn't explicitly convert floating point numbers to integers when they are passed in as an array index. This is in part so it can natively support associative arrays (dictionaries). You can see more about this in QBJS Fun Fact #3. RE: QBJS Swimming fish with Kelp - bplus - 08-15-2023 (08-15-2023, 01:23 PM)dbox Wrote: Not pestering at all @bplus, happy to help! @dbox Eeeh! I thought things would get "fixed" automatically because the Kelp array has the _Unsigned Long Type = only positive integers. ReDim Shared kelp(sw, sh) As _Unsigned Long wait this FIX was needed??? r = Fix(Int(Rnd * 23) + 1) why doesn't INT alone fix it? You have to FIX a number already made integer? hmm.. the +1 is + .99999 or 1.000001 ie float? Sorry don't mean to be argumentative but I remember things better if they make sense to me. RE: QBJS Swimming fish with Kelp - dbox - 08-15-2023 (08-15-2023, 02:41 PM)bplus Wrote: @dbox Eeeh! I thought things would get "fixed" automatically because the Kelp array has the _Unsigned Long Type = only positive integers.I'm afraid that only affects the value stored in the array. The reason the Fix() is needed is due to the fact that there are places where floating point values were passed in as the index to the array. So, here's a simple example to illustrate the point. If you run this in QB64: Code: (Select All)
It will print: Code: (Select All) 30 However, if you run the same example in QBJS it will print: Code: (Select All) 20 (08-15-2023, 02:41 PM)bplus Wrote: wait this FIX was needed???Ha, no, not in this case. I must have just got carried away with calls to Fix() (08-15-2023, 02:41 PM)bplus Wrote: Sorry don't mean to be argumentative but I remember things better if they make sense to me.I'm all for spirited discussions and I don't mind critique. That's the kind of feedback I need to make QBJS better. RE: QBJS Swimming fish with Kelp - CharlieJV - 08-15-2023 Quote:I must have just got carried away with calls to Fix() Ah, "fixated", happens to the best of us at times. Groan ... RE: QBJS Swimming fish with Kelp - dbox - 08-15-2023 The more I think about it the more inclined I am to change the way this is working in the next release of QBJS to increase compatibility with QB64. I think instead of extending the array to also support associative arrays (dictionaries), I'll pull this functionality out into a new type called Dictionary. Then I can implicitly convert any index values passed to an array to an integer, just as in QB64. |