a roguelike game converted from cpp to FB

Game development specific discussions.
ron77
Posts: 213
Joined: Feb 21, 2019 19:24

a roguelike game converted from cpp to FB

Post by ron77 »

hello it's late at night and my brain is already like jelly :( :-/

i was trying to convert a roguelike game from c++ to freebasic i got to the point where i cannot code or think straight anymore

i got to the point where the program is suppose to print to the cmd a level (loaded from a text file) and process it allowing the player "@" to move with keypresses on w s a d yet funny thing it compiles but doesn't run and i have no clue as to why as my brain is dry and fuzzy... the c++ tutorial is over 2 hours long i got to about 40 minutes or so where the player can move but i can't - i need help.

here is the tutorial as a reference:
https://youtu.be/tVWckBaB5xo?t=2889

tbh - the guy who teaches the tutorial is not that great he's teaching outdated c++ programming conventions even for 2014 and he's moving too fast and his voice is annoying...

here is the zip folder of the project (up to minute 48 of the tutorial)
https://www.dropbox.com/s/dk3gx3evccijc ... 2.zip?dl=0

i hope someone could just download the project and check it out and see why it's compiling but not running maybe i didn't noticed something the teacher did in the tutorial so something is missing in my code (compared to the tutorial)...

any help will be appreciated...

ron77

p.s. - 2 am (way off my bedtime)

seem i made some progress it's a run time error!

Code: Select all

Aborting due to runtime error 7 (null pointer access) at line 52 of D:\repo\FreeBasic_Projects\fb_roguelike_game_2\fb_roguelike_game_2\Level.bi::LOAD()
and it points to this sub

Code: Select all

SUB Level.load(fileName AS STRING, byref player AS player)
   DIM AS STRING r
   DIM h AS LONG = FREEFILE
   OPEN fileName FOR INPUT AS h
   WHILE NOT EOF(h)
      LINE INPUT #h, r
      sappend(this._levelData(), r)
   WEND
   CLOSE h
   DIM tile AS string
   FOR i AS INTEGER = 0 TO UBOUND(this._levelData)
      FOR j AS INTEGER = 0 TO LEN(this._levelData(i))
         tile = CHR(this._levelData(i)[j])'<----- where the runtime error happens
         SELECT CASE tile
            CASE "@"
            player.setPosition(j, i)
            CASE "."
            CASE "#"
               
            
         END SELECT
      NEXT
   NEXT
   
END SUB
it seems that i need to figure out how to loop each row of string in the _levelData() array and finding the row and column of each character whith out causing a runtime error or a upset the compiler :-/ any suggestions?
Last edited by ron77 on Apr 10, 2021 15:17, edited 2 times in total.
ron77
Posts: 213
Joined: Feb 21, 2019 19:24

Re: need help coding a roguelike game

Post by ron77 »

okay - i woke up early in the morning without sleeping enough

went straight back to look at the runtime error so... i'v tried this in the sub

Code: Select all

SUB Level.load(fileName AS STRING, byref player AS player)
   DIM AS STRING r
   DIM h AS LONG = FREEFILE
   OPEN fileName FOR INPUT AS h
   WHILE NOT EOF(h)
      LINE INPUT #h, r
      sappend(this._levelData(), r)
   WEND
   CLOSE h
   DIM tile AS string
   FOR i AS INTEGER = 0 TO UBOUND(this._levelData)
      FOR j AS INTEGER = 0 TO LEN(this._levelData(i))
         'tile = CHR(this._levelData(i)[j])<-----changed this
         tile = MID(this._levelData(i), j, 1)'<-------to this

         SELECT CASE tile
            CASE "@"
            player.setPosition(j, i)
            CASE "."
            CASE "#"
               
            
         END SELECT
      NEXT
   NEXT
   
END SUB


now the code compiles and run but i get a black screen :-/ ...

any ideas on how to help me?

I STAND CORRECTED IT WORKS!!! YEAH!!! FINALLY!!!
the black screen is just waiting all you need to do is press a key and then it starts and the level is printed and processed and the player can move!!!
YEAHHHHH!
jdebord
Posts: 547
Joined: May 27, 2005 6:20
Location: Limoges, France
Contact:

Re: need help coding a roguelike game

Post by jdebord »

Richard Clark made a very good tutorial in FreeBASIC :

https://users.freebasic-portal.de/rdc/tutorials.html
ron77
Posts: 213
Joined: Feb 21, 2019 19:24

Re: need help coding a roguelike game

Post by ron77 »

well looks like i've party too soon...

i went on with the tutorials to add enemies (monsters) with a enemy class both player class and enemy have constructors so i'm getting errors about duplicate definitions

here is the tutorial at time 01:20 for reference:
https://youtu.be/tVWckBaB5xo?t=5043

here is the errors i'm getting:

Code: Select all

D:\FreeBASIC-1.07.1-win32\fbc -s console -gen gas -Wc -Ofast -exx "fb_roguelike_game_2.bas"
D:\repo\FreeBasic_Projects\fb_roguelike_game_2\fb_roguelike_game_2\Player.bi(38) error 4: Duplicated definition, at parameter 3 (attack) of PLAYER.constructor(as integer, as integer, as integer, as integer, as integer) in 'CONSTRUCTOR Player(level AS INTEGER, health AS INTEGER, attack AS INTEGER, defense AS INTEGER, xp AS integer)'
D:\repo\FreeBasic_Projects\fb_roguelike_game_2\fb_roguelike_game_2\Player.bi(42) error 42: Variable not declared, defense in 'this._defense = defense'
D:\repo\FreeBasic_Projects\fb_roguelike_game_2\fb_roguelike_game_2\Player.bi(43) error 42: Variable not declared, xp in 'this._experience = xp'
D:\repo\FreeBasic_Projects\fb_roguelike_game_2\fb_roguelike_game_2\Player.bi(62) error 147: Default types or suffixes are only valid in -lang deprecated or fblite or qb, found '=' in 'dim attackRoll = INT(RND_RANGE(0, this._attack))'
D:\repo\FreeBasic_Projects\fb_roguelike_game_2\fb_roguelike_game_2\Player.bi(79) error 4: Duplicated definition, at parameter 1 (attack) of TAKEDAMAGE() in 'FUNCTION Player.TakeDamage(attack AS INTEGER) AS INTEGER'
D:\repo\FreeBasic_Projects\fb_roguelike_game_2\fb_roguelike_game_2\Player.bi(80) error 3: Expected End-of-Line, found '-' in 'attack -= this._defense'
D:\repo\FreeBasic_Projects\fb_roguelike_game_2\fb_roguelike_game_2\enemy.bi(41) error 4: Duplicated definition, at parameter 4 (attack) of ENEMY.constructor(as string, as string, as integer, as integer, as integer, as integer, as integer) in 'CONSTRUCTOR Enemy(name1 AS STRING, tile AS STRING, level AS INTEGER, attack AS INTEGER,defense AS INTEGER, health AS INTEGER, xp AS INTEGER)'
D:\repo\FreeBasic_Projects\fb_roguelike_game_2\fb_roguelike_game_2\enemy.bi(46) error 9: Expected expression, found 'defense' in 'this._defense = defense'
D:\repo\FreeBasic_Projects\fb_roguelike_game_2\fb_roguelike_game_2\enemy.bi(47) error 42: Variable not declared, health in 'this._health = health'
D:\repo\FreeBasic_Projects\fb_roguelike_game_2\fb_roguelike_game_2\enemy.bi(48) error 9: Expected expression, found 'xp' in 'this._experienceValue = xp'
D:\repo\FreeBasic_Projects\fb_roguelike_game_2\fb_roguelike_game_2\enemy.bi(48) error 133: Too many errors, exiting

Build error(s)
i checked and doubled checked and i don't seem to understand what i'm doing wrong or what is wrong...

here is the player.bi file code

Code: Select all

TYPE Player
   PRIVATE:
   _x AS INTEGER
   _y AS INTEGER
   _level AS INTEGER
   _health AS INTEGER
   _attack AS INTEGER
   _defense AS INTEGER
   _experience AS INTEGER
   
   PUBLIC:
   
   DECLARE CONSTRUCTOR()
   DECLARE DESTRUCTOR()
   DECLARE CONSTRUCTOR(level AS INTEGER, health AS INTEGER, attack AS INTEGER, defense AS INTEGER, xp AS integer)
   
   'setters
   DECLARE SUB setPosition(x AS INTEGER, y AS INTEGER)
   
   'getters
   DECLARE SUB getPosition(byref x AS INTEGER,byref  y AS INTEGER)
   
   DECLARE FUNCTION attack() AS INTEGER
   DECLARE SUB addExperience(xp AS INTEGER)
   DECLARE FUNCTION TakeDamage(attack AS INTEGER) AS INTEGER
   
END TYPE

CONSTRUCTOR Player()
this._x = 0
this._y = 0
END CONSTRUCTOR

DESTRUCTOR Player()

END DESTRUCTOR

CONSTRUCTOR Player(level AS INTEGER, health AS INTEGER, attack AS INTEGER, defense AS INTEGER, xp AS integer)
this._level = level
this._health = health
this._attack = attack
this._defense = defense
this._experience = xp
END CONSTRUCTOR

SUB Player.setPosition(x AS INTEGER, y AS INTEGER)
   this._x = x
   this._y = y
END SUB

SUB Player.getPosition(BYref x AS INTEGER,BYREF  y AS INTEGER)
   x = this._x
   y = this._y
END SUB

Function rnd_range (first As Double, last As Double) As Double
    RETURN Rnd * (last - first) + first
End FUNCTION


FUNCTION Player.attack() AS INTEGER
   dim attackRoll = INT(RND_RANGE(0, this._attack))
   RETURN attackRoll
END FUNCTION

SUB Player.addExperience(xp AS INTEGER)
   this._experience += xp
   WHILE (this._experience > 50)
      PRINT "leveled up!"
      this._experience -= 50
      this._attack += 50
      this._defense += 5
      this._health += 10
      this._level += 1
      SLEEP
   WEND
END SUB

FUNCTION Player.TakeDamage(attack AS INTEGER) AS INTEGER
   attack -= this._defense
   IF (attack > 0) THEN
      this._health -= attack
      IF (this._health <= 0) THEN
         RETURN 1
      ENDIF
   
   ENDIF
   RETURN 0
END FUNCTION
here is enemy.bi file code

Code: Select all


TYPE Enemy
   
   PUBLIC:
    declare CONSTRUCTOR()
    DECLARE DESTRUCTOR()
   DECLARE CONSTRUCTOR(name1 AS STRING, tile AS STRING, level AS INTEGER, attack AS INTEGER,defense AS INTEGER, health AS INTEGER, xp AS INTEGER)
   'setters
   DECLARE SUB setPosition(x AS INTEGER, y AS INTEGER)
   
   'getters
   DECLARE SUB getPosition(byref x AS INTEGER,byref  y AS INTEGER)
   DECLARE FUNCTION attack() AS INTEGER
   
   DECLARE FUNCTION TakeDamage(attack AS INTEGER) AS INTEGER
   
   
   PRIVATE:
   _name AS STRING
   _tile AS String
   _x AS INTEGER
   _y AS INTEGER
   _level AS INTEGER
   _attack AS Integer
   _defense AS INTEGER
   _health AS INTEGER
   _experienceValue AS integer
   
   
END TYPE

CONSTRUCTOR Enemy()

END CONSTRUCTOR

DESTRUCTOR Enemy()

END DESTRUCTOR

CONSTRUCTOR Enemy(name1 AS STRING, tile AS STRING, level AS INTEGER, attack AS INTEGER,defense AS INTEGER, health AS INTEGER, xp AS INTEGER)
   this._name = name1
   this._tile = tile
   this._level = level
   this._attack = attack
   this._defense = defense
   this._health = health
   this._experienceValue = xp
END CONSTRUCTOR

SUB Enemy.setPosition(x AS INTEGER, y AS INTEGER)
   this._x = x
   this._y = y
END SUB

SUB Enemy.getPosition(BYref x AS INTEGER,BYREF  y AS INTEGER)
   x = this._x
   y = this._y
END SUB

Function rnd_range (first As Double, last As Double) As Double
    RETURN Rnd * (last - first) + first
End FUNCTION


FUNCTION Enemy.attack() AS INTEGER
   STATIC attackRoll = INT(RND_RANGE(0, this._attack))
   RETURN attackRoll
END FUNCTION

FUNCTION Enemy.TakeDamage(attack AS INTEGER) AS INTEGER
   attack -= this._defense
   IF (attack > 0) THEN
      this._health -= attack
      IF (this._health <= 0) THEN
         RETURN this._experienceValue
      ENDIF
   
   ENDIF
   RETURN 0
END FUNCTION
can someone please explain what is wrong and what does those errors mean?
ron77
ron77
Posts: 213
Joined: Feb 21, 2019 19:24

Re: need help coding a roguelike game

Post by ron77 »

well managed to resolved all the errors and make the game compile and run BUT!... now the print of the level is flickering for some reason....

:-/ :-( i'm just about to give up on this roguelike game conversion from c++ to freebasic... :(
ron77
Posts: 213
Joined: Feb 21, 2019 19:24

Re: need help coding a roguelike game

Post by ron77 »

well managed to get over and fix the flickering and the game works... but i still need to add the monsters movement and for then to attack the player... i'll take a break and return to further on with this game...
ron77
Posts: 213
Joined: Feb 21, 2019 19:24

Re: need help coding a roguelike game

Post by ron77 »

well i've worked further on this tutorial - seems like two steps forward one step backwards

i've added the monster move and AI to the monsters (enemies ?? monsters?? ) now i have this runtime error:

Code: Select all

Aborting due to runtime error 6 (out of bounds array access) at line 130 of D:\repo\FreeBasic_Projects\fb_roguelike_game_2\fb_roguelike_game_2\Level.bi::GETTILE()
here is where i lasted in the tutorial for reference: (almost done!)
https://youtu.be/tVWckBaB5xo?t=6940

and here is the code for Level.bi (where the runtime happens!!!!!!!!!)

Code: Select all

#INCLUDE ONCE "player.bi"
#INCLUDE ONCE "enemy.bi"

TYPE Level
   PUBLIC:
   DECLARE CONSTRUCTOR()
   DECLARE DESTRUCTOR()
   
   DECLARE SUB sappend(arr() AS STRING, temp AS STRING)
   DECLARE SUB eappend(arr() AS enemy, temp AS enemy)
   DECLARE SUB load(fileName AS STRING, BYREF player AS player)
   
   DECLARE SUB printLevel()
   
   DECLARE SUB Moveplayer(k AS STRING,BYREF player AS player)
   DECLARE FUNCTION getTile(x AS INTEGER, y AS INTEGER) AS STRING
   
   DECLARE SUB setTile(x AS INTEGER, y AS INTEGER, char AS STRING)
   DECLARE SUB updateEnemies(BYREF player AS player)
   
   PRIVATE:
   REDIM _levelData(0) AS STRING
   REDIM _enemies(0) AS Enemy
   DECLARE SUB processPlayerMove(BYREF player AS player, targetY AS INTEGER, tragetY AS INTEGER)
   DECLARE function battleMonster(BYREF player AS player, targetX AS INTEGER, tragetY AS INTEGER) AS INTEGER
   DECLARE SUB processMonsterMove(BYREF player AS player, monsterIndex AS INTEGER,targetY AS INTEGER, tragetY AS INTEGER)
END TYPE

CONSTRUCTOR Level()

END CONSTRUCTOR

DESTRUCTOR Level()

END DESTRUCTOR

sUB Level.sappend(arr() AS STRING, temp AS STRING)
   REDIM PRESERVE arr((LBOUND(arr)) TO (UBOUND(arr)+ 1))
   arr(UBOUND(arr)) = temp
END SUB

sUB Level.eappend(arr() AS enemy, temp AS enemy)
   REDIM PRESERVE arr((LBOUND(arr)) TO (UBOUND(arr)+ 1))
   arr(UBOUND(arr)) = temp
END SUB


SUB Level.load(fileName AS STRING, byref player AS player)
   DIM AS STRING r
   DIM h AS LONG = FREEFILE
   OPEN fileName FOR INPUT AS h
   WHILE NOT EOF(h)
      LINE INPUT #h, r
      sappend(this._levelData(), r)
   WEND
   CLOSE h
   DIM tile AS string
   FOR i AS INTEGER = 0 TO UBOUND(this._levelData)
      FOR j AS INTEGER = 0 TO LEN(this._levelData(i))
         tile = MID(this._levelData(i), j, 1)

         SELECT CASE tile
            CASE "@"
            player.setPosition(j, i)
            CASE "S"
               DIM s AS Enemy
               s.CONSTRUCTOR("sanke", tile, 1,1,1,1,1)
               eappend(this._enemies(),s)
               this._enemies(UBOUND(this._enemies)).setPosition(j,i) 
            CASE "g"
               DIM g AS Enemy
               g.CONSTRUCTOR("goblin", tile, 2,10,5,35,50)
               eappend(this._enemies(), g)
                this._enemies(UBOUND(this._enemies)).setPosition(j,i)  
            CASE "O"
               DIM o AS Enemy
               o.CONSTRUCTOR("ogre", tile, 4,20,20,200,500)
               eappend(this._enemies(), o) 
                this._enemies(UBOUND(this._enemies)).setPosition(j,i) 
            CASE "B"
               DIM b AS Enemy
               b.CONSTRUCTOR("bandit", tile, 3,15,10,100,250)
               eappend(this._enemies(), b)
                this._enemies(UBOUND(this._enemies)).setPosition(j,i) 
            CASE "D"
               DIM d AS Enemy
               d.CONSTRUCTOR("dragon", tile, 100,2000,2000,2000,500000)
               eappend(this._enemies(), d) 
                this._enemies(UBOUND(this._enemies)).setPosition(j,i) 
               
            
         END SELECT
      NEXT
   NEXT
   
END SUB

SUB Level.printLevel()
   CLS
   FOR i AS INTEGER = 0 TO UBOUND(this._levelData)
      PRINT this._levelData(i)
   NEXT
   SLEEP(1000)
END SUB

SUB Level.Moveplayer(k AS STRING,BYREF player AS player)
   
   DIM AS INTEGER PlayerX, PlayerY
   player.getPosition(PlayerX, PlayerY)
   
   
   
   
   SELECT CASE k
      CASE "w"
         this.processPlayerMove(player,PlayerX, PlayerY - 1)
         
      CASE "s"
         this.processPlayerMove(player,PlayerX, PlayerY + 1)
      CASE "a"
         this.processPlayerMove(player,PlayerX - 1, PlayerY)
      CASE "d"
         this.processPlayerMove(player,PlayerX + 1, PlayerY)
      
         
   END SELECT
END SUB

FUNCTION Level.getTile(x AS INTEGER, y AS INTEGER) AS STRING
   RETURN MID(this._levelData(y), x, 1)'<---- this is where the runtime error happens :(
   
END FUNCTION


SUB Level.setTile(x AS INTEGER, y AS INTEGER, char AS STRING)
   MID(this._levelData(y), x, 1) = char
END SUB


SUB Level.processPlayerMove(BYREF player AS player, targetX AS INTEGER, targetY AS INTEGER)
   
   DIM AS INTEGER playerX, playerY
   player.getPosition(playerX,playerY)
   
   DIM AS STRING moveTile = getTile(targetX, targetY)
   
   SELECT CASE moveTile
            CASE "#"
               PRINT "you ran into a wall!"
               SLEEP
            CASE "."
               player.setPosition(targetX,targetY)
               setTile(playerX, playerY, ".")
               setTile(targetX,targetY, "@")
      CASE ELSE
         battleMonster(player, targetX, targetY)
         END SELECT
END SUB


function Level.battleMonster(BYREF player AS player, targetX AS INTEGER, targetY AS INTEGER) AS INTEGER
   
   DIM AS INTEGER enemyX, enemyY, playerX, playerY
   DIM AS INTEGER attackRoll, attackResult
   
   PLAYER.GETPOSITION(playerX,playerY)
   
   FOR i AS INTEGER = 0 TO UBOUND(this._enemies)
      this._enemies(i).getPosition(enemyX, enemyY)
      IF (targetX = enemyX AND targetY = enemyY) THEN
         attackRoll = PLAYER.ATTACK()
         PRINT "player attacked monster with roll of " & STR(attackroll)
         attackResult = this._enemies(i).takeDamage(attackRoll)
         IF (attackResult <> 0) THEN
            setTile(targetX,targetY, ".")
            printlevel()
            PRINT "monster died!"
            this._enemies(i).deadMonster()
            'i -= 1
            sleep
            Player.addExperience(attackResult)
            
            RETURN 0
         ENDIF
         attackRoll = this._enemies(i).attack()
         PRINT "monster attacked player with the roll of " & STR(attackroll)
         attackResult = Player.takeDamage(attackRoll)
         IF (attackResult <> 0) THEN
            setTile(playerX,playerY, "X")
            printlevel()
            PRINT "you died!"
            sleep
            END           
            RETURN 0
         ENDIF
         SLEEP
         RETURN 0
      ENDIF
   NEXT
   
END FUNCTION

SUB Level.updateEnemies(BYREF player AS player)
   
   DIM aiMove AS STRING
   DIM AS INTEGER playerX, playerY, enemyX, enemyY
   
   PLAYER.GETPOSITION(playerX, playerY)
   
   FOR i AS INTEGER = 0 TO UBOUND(this._enemies)
      aiMove = this._enemies(i).getMove(playerX, playerY)
      this._enemies(i).getPosition(enemyX,enemyY) 
   SELECT CASE aiMove
      CASE "w"
         this.processMonsterMove(player,i,enemyX, enemyY - 1)
         
      CASE "s"
         this.processMonsterMove(player,i,enemyX, enemyY + 1)
      CASE "a"
         this.processMonsterMove(player,i,enemyX - 1, enemyY)
      CASE "d"
         this.processMonsterMove(player,i,enemyX + 1, enemyY)
      
         
   END SELECT
   NEXT
   
END SUB


SUB Level.processMonsterMove(BYREF player AS player, monsterIndex AS INTEGER, targetX AS INTEGER, targetY AS INTEGER)
   DIM AS INTEGER playerX, playerY, enemyX, enemyY
   player.getPosition(playerX,playerY)
   this._enemies(monsterIndex).getPosition(enemyX,enemyY)
   DIM AS STRING moveTile = getTile(targetX, targetY)
   
   SELECT CASE moveTile
            CASE "#"
               
            CASE "."
               this._enemies(monsterIndex).setPosition(targetX,targetY)
               setTile(enemyX, enemyY, ".")
               setTile(targetX,targetY, this._enemies(monsterIndex).getTile())
      CASE ELSE
         
         END SELECT
END SUB


i've upload the project to github to a public repository in the hope that some one will take the time and trouble and help me finish this dam game...
the github repo:
https://github.com/ronblue/fb_rogelike_2

here is how the program runs until it crashes:
https://sendvid.com/7tbt7zya

any help will be appreciated

ron77
Last edited by ron77 on Apr 09, 2021 16:42, edited 1 time in total.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: need help coding a roguelike game

Post by MrSwiss »

Without looking at the code (original C++) I'm pretty certain, that all your Integer's are not correct.

C/C++ int is NOT = Integer
C/C++ int is = Long (in FB)

This may or not make a difference ... also see: FB's numeric data-type(s) read all 4 posts (currently)

Remark: Declare(d) CTOR/DTOR must be implemented even if 'empty' whenever an overload exists.
(default's are in this case not any longer automatically created)
ron77
Posts: 213
Joined: Feb 21, 2019 19:24

Re: need help coding a roguelike game

Post by ron77 »

hello MrSwiss...

thank you for taking the time and effort to help me...

i've changed al the integer's in my code to long but the runtime error still remains - what else should you think i should change?
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: need help coding a roguelike game

Post by MrSwiss »

Hello ron77,

I'm not into C++ otherwise, I wouldn't be sticking around here ;-)
Sadly my interests are outside of games, generally.

Advice: use a Debugger in order to solve such errors, see: FB debugger : 2.98.1 32/64 BIT ..... (2021/01/30) made by member SARG.
badidea
Posts: 2591
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: need help coding a roguelike game

Post by badidea »

ron77 wrote:discord is highly addictive to me i spent too many hours on it more that i intended instead of actually coding...
ron77 wrote:hello it's late at night and my brain is already like jelly :( :-/
ron77 wrote:okay - i woke up early in the morning without sleeping enough
... many more posts ...

It is allowed to take a break you know :-)
ron77
Posts: 213
Joined: Feb 21, 2019 19:24

Re: need help coding a roguelike game

Post by ron77 »

okay...

i got help from hesekiel on the discord FB server (yes i'm still on discord)

seemed that _levelData() array was being out of bound

therefore i changed the getTile() function to this

Code: Select all

FUNCTION Level.getTile(x AS long, y AS LONG) AS STRING
   if y>ubound(this._levelData) then PRINT "y is larger then ubound"
if y<lbound(this._levelData) then PRINT "y is smaller then lbound" 
   IF y <= LBOUND(this._levelData) THEN y = LBOUND(this._levelData)
      IF y >= UBOUND(this._levelData) then y = UBOUND(this._levelData)
   RETURN MID(this._levelData(y), x, 1)'<---- this is where the runtime error happens :(
END FUNCTION
that did the trick and now the program doesn't crash from run time errors of out of bound :)
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: need help coding a roguelike game

Post by MrSwiss »

ron77 wrote:seemed that _levelData() array was being out of bound
You can also use: -exx (compiler switch) on CLI/IDE, to detect such things ...

Btw: sometimes, time is better spent reading FB-documentation, than just chatting away ...
ron77
Posts: 213
Joined: Feb 21, 2019 19:24

Re: need help coding a roguelike game

Post by ron77 »

well...

the project is done... finished... completed...

here is the repository on github...
https://github.com/ronblue/fb_rogelike_2

the only problem i can think of is that in the c++ tutorial the dude uses a vector of monsters while i use a dynamic array of monsters so when a monster is killed in c++ he removes that monster from the vector while in my code in FB the monster just disappear but still remains (like a ghost monster) since i don't know how to remove that monster from the array (i don't know how to use linked lists yet )

anyway for what's it worth it was interesting to code this... now maybe i'll take a break until i'll find something else to code...

ron77
badidea
Posts: 2591
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: a roguelike game converted from cpp to FB

Post by badidea »

Off-topic: Ron, if you have specific questions concerning OOP, why not start a topic on this forum? Answers usually come quickly, unless no one is interested
Post Reply