|
Array of Strings - Empty pointer error
#448365
02/01/15 19:50
02/01/15 19:50
|
Joined: Nov 2006
Posts: 497 Ohio
xbox
OP
Senior Member
|
OP
Senior Member
Joined: Nov 2006
Posts: 497
Ohio
|
I have an array of strings defined as:
STRING* bg_sounds[12];
bg_sounds[0] = "song1.mp3";
...
bg_sounds[11] = "song11.mp3";
before the main function I have a handle: at the end of my main function I have:
bg_handle = media_play(bg_sounds[0], NULL, 100);
It compiles and runs, but immediately I'm greeted with an "Empty pointer in main" error. If I comment out the media_play line, the game runs so I know that's the line causing issue but I am at a loss as to why. Any help would be greatly appreciated. Also, I've replaced bg_sounds[0] in the media_play with the string itself and it works but with the array it gives the error.
|
|
|
Re: Array of Strings - Empty pointer error
[Re: xbox]
#448366
02/01/15 19:52
02/01/15 19:52
|
Joined: May 2009
Posts: 5,370 Caucasus
3run
Senior Expert
|
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
Maybe file wasn't found? Edit: sorry, I was too blinded at the first look, try this:
STRING* names[10];
void main(){
str_cpy(names[0], "song1.mp3");
var bg_handle = media_play(bg_sounds[0], NULL, 100);
}
Thing is, that you can't set string like "string = "blahblah", you have to use those 'str_' function, to deal with strings. I hope this helps Greets
Last edited by 3run; 02/01/15 20:01. Reason: 123
|
|
|
Re: Array of Strings - Empty pointer error
[Re: txesmi]
#448371
02/01/15 22:30
02/01/15 22:30
|
Joined: May 2009
Posts: 5,370 Caucasus
3run
Senior Expert
|
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
txesmi was faster than me The thing is, that 'STRING* blah[3];' will create only an array of empty pointers, to use them you need to allocate strings and save them into those pointers. This what I've just came out with:
STRING* names[99];
void main(){
int i = 0;
for(i=0; i < 99; i++){
names[i] = str_create("");
}
str_cpy(names[0], "Arty - Kate (Original Mix).mp3");
media_play(names[0], NULL, 100);
while(1){
draw_text(names[0], 10, 10, COLOR_WHITE);
wait(1);
}
}
There might be some typos, I'm using my cellphone to write this post. I hope it helps Greets
|
|
|
Re: Array of Strings - Empty pointer error
[Re: txesmi]
#448373
02/02/15 04:42
02/02/15 04:42
|
Joined: Nov 2006
Posts: 497 Ohio
xbox
OP
Senior Member
|
OP
Senior Member
Joined: Nov 2006
Posts: 497
Ohio
|
Wow, okay. Thanks for the responses! I hadn't realized that the STRING type was so needy I hadn't even considered the TEXT object, but that is almost exactly what I wanted to accomplish so I guess I'll just change it to a TEXT object and not have to worry about it. Thanks guys! I really appreciate it!
Last edited by xbox; 02/02/15 04:42.
|
|
|
|