1. Subscript Error

Hi all,

I am having trouble with this for loop and subscript atom issue. attempt to subscript an atom in subscript of #1 of 'buildings'

Trying to make a euphoria version of this: https://github.com/raysan5/raylib/blob/master/examples/core/core_2d_camera.c

Note: A rectangle struct from Raylib is Rectangle(x,y,width,height) Using Greg's FFI library.

public constant Rectangle = define_c_struct({ 
	C_FLOAT, --x top-left corner pos x 
	C_FLOAT, --y top-left corner pos y 
	C_FLOAT, --width 
	C_FLOAT --height 
}) 
include raylib.e 
include std/ffi.e 
 
constant MAX_BUILDINGS = 100 
 
constant WIDTH = 800 
constant HEIGHT = 450 
 
InitWindow(WIDTH,HEIGHT,"2D Camera") 
 
enum player_x = 1, 
	 player_y, 
	 player_width, 
	 player_height 
	  
enum building_x = 1, 
	 building_y, 
	 building_width, 
	 building_height 
	  
enum colorb_r = 1, 
	 colorb_g, 
	 colorb_b, 
	 colorb_a 
 
sequence player = {400,280,40,40} --Rectangle 
sequence buildings = {0,0,0,0} --Rectangle 
sequence buildColors = {0,0,0,0} --Color 
 
integer spacing = 0 
 
for i = 1 to MAX_BUILDINGS do 
	buildings[i][building_width] = GetRandomValue(50,200) --error comes from this line 
end for 
new topic     » topic index » view message » categorize

2. Re: Subscript Error

Icy_Viking said...

Hi all,

I am having trouble with this for loop and subscript atom issue. attempt to subscript an atom in subscript of #1 of 'buildings'

Trying to make a euphoria version of this: https://github.com/raysan5/raylib/blob/master/examples/core/core_2d_camera.c

Note: A rectangle struct from Raylib is Rectangle(x,y,width,height) Using Greg's FFI library.

public constant Rectangle = define_c_struct({ 
	C_FLOAT, --x top-left corner pos x 
	C_FLOAT, --y top-left corner pos y 
	C_FLOAT, --width 
	C_FLOAT --height 
}) 
include raylib.e 
include std/ffi.e 
 
constant MAX_BUILDINGS = 100 
 
constant WIDTH = 800 
constant HEIGHT = 450 
 
InitWindow(WIDTH,HEIGHT,"2D Camera") 
 
enum player_x = 1, 
	 player_y, 
	 player_width, 
	 player_height 
	  
enum building_x = 1, 
	 building_y, 
	 building_width, 
	 building_height 
	  
enum colorb_r = 1, 
	 colorb_g, 
	 colorb_b, 
	 colorb_a 
 
sequence player = {400,280,40,40} --Rectangle 
sequence buildings = {0,0,0,0} --Rectangle 
sequence buildColors = {0,0,0,0} --Color 
 
integer spacing = 0 
 
for i = 1 to MAX_BUILDINGS do 
	buildings[i][building_width] = GetRandomValue(50,200) --error comes from this line 
end for 

How many buildings? (Or, loks like you've only defined one so for)

Cheers

Chris

new topic     » goto parent     » topic index » view message » categorize

3. Re: Subscript Error

Icy_Viking said...
https://github.com/raysan5/raylib/blob/master/examples/core/core_2d_camera.c said...

Rectangle buildings[MAX_BUILDINGS] = { 0 };

sequence buildings = {0,0,0,0} 

Your buildings is a sequence of 4 atoms, it needs to be more like

sequence buildings = repeat({0,0,0,0},MAX_BUILDINGS) 

Each buildings[i] might need to be a Rectangle/allocated memory instead
I suspect you'll have the same problem with buildColors

new topic     » goto parent     » topic index » view message » categorize

4. Re: Subscript Error

petelomax said...
Icy_Viking said...
https://github.com/raysan5/raylib/blob/master/examples/core/core_2d_camera.c said...

Rectangle buildings[MAX_BUILDINGS] = { 0 };

sequence buildings = {0,0,0,0} 

Your buildings is a sequence of 4 atoms, it needs to be more like

sequence buildings = repeat({0,0,0,0},MAX_BUILDINGS) 

Each buildings[i] might need to be a Rectangle/allocated memory instead
I suspect you'll have the same problem with buildColors

Thanks, the repeat function worked.

EDIT: Well Greg already made a working example some time ago. https://github.com/ghaberek/libffi-euphoria/blob/main/examples/core_2d_camera.ex

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu