Dubbsta
Active member
- Joined
- Jul 13, 2017
- Messages
- 208
trying to draw a map of blocks but i get a memory access violation
Code:
Strict
Import mojo
Class Block
Field x:Int,y:Int
Field size:Int
Method New(x:Int,y:Int,size:Int)
Self.x = x
Self.y = y
Self.size = size
End
Method draw:Void()
End
End
Class Grass Extends Block
Method New(x:Int,y:Int,size:Int)
Super.New(x,y,size)
End
Method draw:Void()
SetColor(0,255,0)
DrawRect(x,y,size,size)
End
End
Class test Extends App
Field grass:Block
Field map:Block[][]
Field width:Int = 2
Field height:Int = 2
Method OnCreate:Int()
SetUpdateRate(60)
map = [[grass,grass],
[grass,grass]]
For Local i:Int = 0 Until height
For Local j:Int = 0 Until width
map[i][j] = New Grass(grass.x * 40,grass.y * 40,40) '<---memory access violation here
End
End
Return 0
End
Method OnUpdate:Int()
Return 0
End
Method OnRender:Int()
Cls 0,0,0
For Local i:Int = 0 Until height
For Local j:Int = 0 Until width
If map[i][j] = grass
grass.draw()
End
End
End
Return 0
End
End
Function Main:Int()
New test()
Return 0
End