Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (AndrewAMD, 7th_zorro, ozgur, Quad), 844 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Array of Strings - Empty pointer error #448365
02/01/15 19:50
02/01/15 19:50
Joined: Nov 2006
Posts: 497
Ohio
xbox Offline OP
Senior Member
xbox  Offline OP
Senior Member

Joined: Nov 2006
Posts: 497
Ohio
I have an array of strings defined as:
Code:
STRING* bg_sounds[12];
bg_sounds[0] = "song1.mp3";
...
bg_sounds[11] = "song11.mp3";


before the main function I have a handle:
Code:
var bg_handle;


at the end of my main function I have:
Code:
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 Offline
Senior Expert
3run  Offline
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:
Code:
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 laugh

Greets

Last edited by 3run; 02/01/15 20:01. Reason: 123

Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: Array of Strings - Empty pointer error [Re: 3run] #448368
02/01/15 21:34
02/01/15 21:34
Joined: Nov 2006
Posts: 497
Ohio
xbox Offline OP
Senior Member
xbox  Offline OP
Senior Member

Joined: Nov 2006
Posts: 497
Ohio
I did just this and now I am getting, "Invalid arguments in main", and "Empty pointer in main".

Re: Array of Strings - Empty pointer error [Re: xbox] #448369
02/01/15 21:50
02/01/15 21:50
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
I'm surprised that it doesn't work on my side too.. I'll do some more tests.


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: Array of Strings - Empty pointer error [Re: 3run] #448370
02/01/15 22:07
02/01/15 22:07
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
The strings creation is needed.

Code:
STRING *strArray[10];

function strArray_create ()
{
   int index=0;
   for ( ; index<10; index+=1 )
      strArray[index] = str_create("");
}

function strArray_remove ()
{
   int index=0;
   for ( ; index<10; index+=1 )
      str_remove ( strArray[index] );
}

function main ()
{
   strArray_create ();
   str_cpy ( strArray[0], "song1.mp3" );
   var hndSong = media_play ( strArray[0], NULL, 100 );
   while ( media_playing ( hndSong ) )
      wait(1);
   strArray_remove ();
   sys_exit ( NULL );
}


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 Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
txesmi was faster than me blush

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:
Code:
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 laugh

Greets


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: Array of Strings - Empty pointer error [Re: 3run] #448372
02/01/15 23:26
02/01/15 23:26
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
you can also use a TEXT struct and forget about allocation and removal.

Code:
TEXT *txtSongs = { string ( "song01.ogg", "song02.ogg" ); }
...
var hndSong = media_play ( (txtSongs.pstring)[1], NULL, 100 );


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 Offline OP
Senior Member
xbox  Offline 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 grin

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.

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1