MSX FUSION-C, Talking about bugs, errors, mistakes

Page 20/21
13 | 14 | 15 | 16 | 17 | 18 | 19 | | 21

By ericb59

Paladin (1015)

ericb59's picture

15-10-2020, 09:23

@raymond
Yes ducasp is right, you cannot replace data in the array Lvl, because it is defined as CONST
So the example code cannot works.
Also, instead using the standard C command 'memcpy' which is written in C, try to use use the equivalent function of fusion-c : MemCopy, which is written in ASM.

By yustmenl

Rookie (25)

yustmenl's picture

21-10-2020, 19:46

I have changed the array to

char * Lvl[169] = {
"Z00","Z00","Z00" etc.

and tried to fill it with:
for (i=0;i<169;++i)
{
MemCopy(Lvl[i],&FileData[(i*3)+charsb4array],3);
}

and i tried with:
for (i=0;i<169;++i)
{
MemCopy(*Lvl[i],&FileData[(i*3)+charsb4array],3);
}

both resulted inin an array completely filled with the last value I tryed to enter in Lvl[i]

so if the last value was B22 the whole array would be filled with this vallue.

sorry for these stupid questions, but we are completely new to C

By ericb59

Paladin (1015)

ericb59's picture

22-10-2020, 11:46

Hi

There is a problem with the type of variable you want to use.
In C, the 'char' is actually a number between 0 and 255
C does not differentiate between a number and an ASCII character.
char a = 65 can mean the variable A is equal to 65, or is equivalent to ASCII character 'A' (65). It all depends on the use you make of the variable.

A string must end with '0' if it is intended to be displayed or treated as a string. 0 indicates the end of the string.

In your example you want to define an array of strings, and be able to modify its datas.
Even if the way you do seems tp work, it's not the right way to do it.
A string array is defined like this:
char Lvl [169] [3]
This means there are 169 elements of 3 characters in the array.
Here's a sample code:

char Lvl[169][4] = {{"A00"},{"B11"},{"C22"}};
char MyString[4]={"X99"};

 printf("\n\r %s", Lvl[0]);
 printf("\n\r %s", Lvl[1]);
 printf("\n\r %s", Lvl[2]);

 MemCopy(Lvl[1],MyString,3);

 printf("\n\r %s", Lvl[0]);
 printf("\n\r %s", Lvl[1]);
 printf("\n\r %s", Lvl[2]);

This will modify the second element of the string array with the content of the variable MyString.

hope this will help you.

By yustmenl

Rookie (25)

yustmenl's picture

22-10-2020, 11:52

Ah thanks, i already thought it was a newbie problem, wil try this!

By ericb59

Paladin (1015)

ericb59's picture

22-10-2020, 14:19

No problem Wink

To demonstrate what I was saying about the 'char' type, if arrays are defined like this, you get the same result.

 char Lvl[169][4]={{65,48,48},{66,49,49},{67,50,50}};
 char MyString[4]={88,57,57};

By yustmenl

Rookie (25)

yustmenl's picture

27-10-2020, 21:52

We build parts of our code thanks to this explanation, and it looks like we are getting it to work.

Thanks again!

By ericb59

Paladin (1015)

ericb59's picture

28-10-2020, 16:28

@yustmeni : Cool Wink Do you want to let us know what you are working on ? -> Call to FUSION-C users & coders

By raymond

Champion (462)

raymond's picture

28-10-2020, 20:49

ericb59 wrote:

@yustmeni : Cool ;) Do you want to let us know what you are working on ? -> Call to FUSION-C users & coders

I already did, our project is called "Elemental Hearts". We are waiting for some more graphics to be available.

By yustmenl

Rookie (25)

yustmenl's picture

31-10-2020, 19:38

raymond wrote:
ericb59 wrote:

@yustmeni : Cool ;) Do you want to let us know what you are working on ? -> Call to FUSION-C users & coders

I already did, our project is called "Elemental Hearts". We are waiting for some more graphics to be available.

Yep we are working on this together, now finishing up the level editor and hopefully, we can start the game soon.

By ericb59

Paladin (1015)

ericb59's picture

10-11-2020, 13:02

The fusion-c 1.2 was updated with some fix.
Fix : bug and corrupted graphics when using sprites on MSX1 Machines.

https://github.com/ericb59/Fusion-C-v1.2

Page 20/21
13 | 14 | 15 | 16 | 17 | 18 | 19 | | 21