About Monkey 2 › Forums › Monkey 2 Programming Help › Help with Pointers.
This topic contains 2 replies, has 2 voices, and was last updated by 
 bigand 1 year, 2 months ago.
- 
		AuthorPosts
 - 
		
			
				
January 23, 2018 at 3:29 pm #13177
Hey all.
Can somebody give me a little help with pointers please?
I am specifically wanting to work with SDL_MIXER and these functions:
Function Mix_LoadMUS:Mix_Music Ptr( file:CString Ptr )
Function Mix_FreeMusic( music:Mix_Music Ptr )
Function Mix_PlayMusic:Int( music:Mix_Music Ptr, loops:Int )I understand pointers in C but I haven’t ever used them in Monkey before, so not sure how I should be declaring or even working with them. I have searched the forum but it just will not go in my thick skull.
Its like the first function above, I can’t even get my head around how I even pass the filename. I know in C it wants:
const char *fileBut just not sure how to translate that to Monkey.
Just getting frustrated I guess as I know its a fingertip away from making sence.
Thanks in advance.
January 23, 2018 at 8:33 pm #13182Monkey pointers are similar to C pointers, only they use ‘Ptr’ instead of ‘*’ and ‘Varptr’ instead of ‘&’, eg:
Monkey1234567Function Main()Local i:Int=10Local p:Int Ptr=Varptr ip[0]*=10Print iEndAlso, you need to use ‘[]’ to dereference a pointer, so ‘p[0]’ is the same as ‘(*p)’ in C.
‘CString’ is a built-in type that should only appear in extern blocks and basically means ‘const char *’. It can be used as if it were a normal monkey2 string. So whenever you see ‘CString’ in a monkey2 extern block, just think ‘const char*’.
Note there is an error in the sdl-mixer file: ‘Function Mix_LoadMUS:Mix_Music Ptr( file:CString Ptr )’ is wrong as ‘CString Ptr’ is actually a ‘const char **’! This should just be ‘file:CString’. I have just pushed a fix for this to the develop branch at github. However, you can always just fix this yourself and update modules if you want.
I have not actually tried the sdl-mixer module myself as it has a dependancy on a shared library for decoding music etc that I wasn’t sure how to build/use. There is however a vsynth demo in bananas that using the module just for playing audio.
January 24, 2018 at 9:14 am #13201Awesome Mark, thats exactly what I needed to read.
The vsynth demo was what got me looking at sdl_mixer in the first place.
As you may remember I had issues with playing a load of OGG files but if I can get the original XM module working, that will save me a LOT of hassle as well as memory (the original XM file with all the music in it is as big as just one OOG file).
 - 
		AuthorPosts
 
You must be logged in to reply to this topic.