kusogaki 2021-01-24 15:24
Let's say, I want my game to have the player's level capped at 99.
Now, I know it can be done easily with
IF LVL>99 THEN LVL=99
But, I actually want the check to be done in the background, at all times. That means, the game will constantly check the player's level, to make sure it doesn't exceed 99.
I know there's no reason to do something like that in a game because you could just do it normally, but I'm curious to know it is possible or not.
I imagine it will be quite hard (or impossible) to implement something like that in a linear game. But like I said before, I have no experience in coding whatsoever so I don't know.
Timo 2021-01-24 15:59
I would write a SUB which increases the level, and always call that instead of LVL=LVL+1. This way it always checks the limit when needed.
IF LVL<99 THEN LVL=LVL+1
was8bit 2021-01-24 16:15 (Edited)
Excellent advice :D
One point though... at the top of your code, add
or whatever variable you want, as otherwise non-global variables inside a SUB are not the same as variables outside the SUB, even if they have the same names!
.... ok, if you always want +1 this is perfect...
I would offer one step further.... for the option of a variable increase (sometimes +1, sometimes +2, maybe random)
IF LVL>99 THEN LVL=99
was8bit 2021-01-24 16:18 (Edited)
I used several examples of how you can use CALL SUB LEVELUP(#)
# can any number, math, and even a variable
All are valid options :)
was8bit 2021-01-24 16:22 (Edited)
Although all of your code must be above the file data (characters, backgrounds,,etc) Subs can be placed anywhere in your code ...
was8bit 2021-01-24 16:30
I want to talk about GLOBAL
Without GLOBAL, all variables and arrays used in your main code are NOT the same as variable and arrays used inside any SUB
So if you use FRAMENUM inside a SUB, and FRAMENUM in your main code, but did NOT have GLOBAL FRAMENUM at the top of your code, then the FRAMENUM inside your SUB does not affect your FRAMENUM outside your code
Also, FRAMENUM inside your SUB losses its value as soon as the SUB code ends, SUB variables do not keep their values, they all always start at 0 each time the SUB is run...
IF, at the top of your code, you write
DIM GLOBAL MAP(99,99)
then PLAYERLEVEL and MAP() array are all available to your main code, as well as to any and all SUBs
was8bit 2021-01-24 16:32
Sorry i wrote so much stuff.. please ask ANY questions, any time :)
kusogaki 2021-01-24 23:31
Thank you so much! These are very useful. I understand better now.
qwaffe 2021-01-25 00:40
LEVEL = MIN(LEVEL + 1, 99)
was8bit 2021-01-25 04:45
@kusogaki, glad to be helpful :)
@qwaffe, all this time, and i never noticed MIN or MAX ;)
Greenpilloz 2021-01-25 13:35
My personal new fav command:
ADD LEVEL, 1, 0 TO 99
(it will loop back to 0 here though)