• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Windows Very bizarre problem with arrays

A

AnotherDoor

Guest
In a nutshell:
My code contains an error that the game does not recognice as an error.


(click to zoom)(original)
In the first picture, I have the autofill function off. So I can with my left mousebutton write those cells, and change the color with wheel. [0 = none, 1 = black, 2 = gray, 3 = white]

The code is simple If the cell under your mouse is 0, then you can draw over it.

Full code (step event):
if (mouse_check_button(mb_left))
{
var mousex = (median(0,mouse_x,room_width));
var mousey = (median(64,mouse_y,room_height-(7*32)));

global.Xwall = floor(mousex/32);
global.Ywall = floor(mousey/32);

show_message("mouse check");


if(global.basetiles[global.Xwall,global.Ywall] == 0)
{

show_message("if statement");


switch(mousewheel)
{
case 1:
scr_paletwall();
break;

case 2:
scr_paletsidewalk();
break;

case 3:
scr_paletroad();
break;
}
}
}



In the second picture I have the autofill function on, which does its job. It gives the bottom row cells their values, and that part of the code works fine. Except: When I try to paint over those zeroes it does not allow me to do so...

I narrowed down the problem a little bit:

In the first picture, both of the highlighted messages where seen. Whereas in the second picture only the first one got shown. Which means, the code knows that the mouse button is pressed, but it thinks that the cell under the mouse is something else than 0.

I think the problem is somewhere in the autofill function:


I KNOW!
I know you are not supposed to store a large chunk of numbers like that. But that is just a temporary solution. The show_message gives the string just like it is writen in the file1 variable. Also to clarify, the room is 40x30 cells, where one cell is 32x32 pixels.
The problem might be in the global.basetiles. But I have checked them and they seem to be identical.

Could the problem be that the "numbers" stored in the array by the autofill are not processed as numbers. For example there is a difference between: car = 1; and car = "1"; If my problem is that, then how to fix it ? Do i need to change the "string_char_at" statement to another ?

Miscs.
- Autofill is called in the creation of the room.
- The draw event looks like this:
var i = 40;
var j = 30;
var k = 0;

repeat(1800)
{

draw_text(i*32,j*32,string(global.basetiles[i,j]));
i -= 1;
if(i == -1)
{
if(j == 2)
{
break;
}

j -= 1;
i = 40;
}
}


Please do ask if you need more data/information
 

TheouAegis

Member
char is a string, so it sets the array position to a string. Your mouse code checks for a real. Yes, there is a huge difference between 1 and "1".
 

TsukaYuriko

☄️
Forum Staff
Moderator
Strings containing reals can be cast to reals using the real function. I suggest looking it up in the manual for reference.
 
Top