PlayAudioStreamForPlayer and Arrays BUG
#1

Good Morning!

I'm working on a system and there seems to be a bug that prevents the script from receiving the correct information from a few arrays I set up.

I'm not entirely knowledgeable on two dimensional arrays, so I came here hoping someone could give me some advice or guide me in the right direction!

Below is a cut from the code.

pawn Код:
if(dialogid == RADIO_GENRE_ROCK)
      {
        if(response)
        {
            foreach(Player, i)
            {
                if(IsPlayerInAnyVehicle(i))
                {
                    new veh = GetPlayerVehicleID(playerid);
                    if(GetPlayerVehicleID(i) == veh)
                    {
                        PlayAudioStreamForPlayer(i, RockStations[listitem][1]);
                        vInfo[veh][rStation] = RockStations[listitem][1];
                        SetPVarInt(i, "Streaming", 1);
                    }
                }
            }
        }
        return 1;
    }
Here is what it displays when I choose the listitem.



That's nowhere near what the ID is supposed to be, as you can see from this bit of code.

pawn Код:
new RockStations [] [] =
{
    {"181.fm - The Buzz!", "http://yp.shoutcast.com/sbin/tunein-station.pls?id=37586"},
    {"Radio Paradise", "http://yp.shoutcast.com/sbin/tunein-station.pls?id=785339"},
    {"181.fm - Awesome 80's", "http://yp.shoutcast.com/sbin/tunein-station.pls?id=785339"},
    {"idobi Radio", "http://yp.shoutcast.com/sbin/tunein-station.pls?id=914897"},
    {"Star.fm - Maximum Rock!", "http://yp.shoutcast.com/sbin/tunein-station.pls?id=108588"},
    {"181.fm - 90's Alternative", "http://yp.shoutcast.com/sbin/tunein-station.pls?id=1034265"},
    {"181.fm - Hard Rock Heaven", "http://yp.shoutcast.com/sbin/tunein-station.pls?id=106750"}
};
( I chose the top one. )

If anyone requires further information, please don't hesitate to ask! I'm in dire need of fixing this!

Thank you!
Reply
#2

It needs to be a 3D array because you also need the lenght of the strings.
pawn Код:
new RockStations[ ][ ][ ] =
{
    {"181.fm - The Buzz!", "http://yp.shoutcast.com/sbin/tunein-station.pls?id=37586"},
    {"Radio Paradise", "http://yp.shoutcast.com/sbin/tunein-station.pls?id=785339"},
    {"181.fm - Awesome 80's", "http://yp.shoutcast.com/sbin/tunein-station.pls?id=785339"},
    {"idobi Radio", "http://yp.shoutcast.com/sbin/tunein-station.pls?id=914897"},
    {"Star.fm - Maximum Rock!", "http://yp.shoutcast.com/sbin/tunein-station.pls?id=108588"},
    {"181.fm - 90's Alternative", "http://yp.shoutcast.com/sbin/tunein-station.pls?id=1034265"},
    {"181.fm - Hard Rock Heaven", "http://yp.shoutcast.com/sbin/tunein-station.pls?id=106750"}
};
Reply
#3

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
It needs to be a 3D array because you also need the lenght of the strings.
pawn Код:
new RockStations[ ][ ][ ] =
{
    {"181.fm - The Buzz!", "http://yp.shoutcast.com/sbin/tunein-station.pls?id=37586"},
    {"Radio Paradise", "http://yp.shoutcast.com/sbin/tunein-station.pls?id=785339"},
    {"181.fm - Awesome 80's", "http://yp.shoutcast.com/sbin/tunein-station.pls?id=785339"},
    {"idobi Radio", "http://yp.shoutcast.com/sbin/tunein-station.pls?id=914897"},
    {"Star.fm - Maximum Rock!", "http://yp.shoutcast.com/sbin/tunein-station.pls?id=108588"},
    {"181.fm - 90's Alternative", "http://yp.shoutcast.com/sbin/tunein-station.pls?id=1034265"},
    {"181.fm - Hard Rock Heaven", "http://yp.shoutcast.com/sbin/tunein-station.pls?id=106750"}
};
I have tried multiple methods in getting this bit of advice to work, but no such luck!
Here is what I have implemented based on your advice. It's still not playing the audio streams as it should. It all seems fine to me, I can't find any problems. I've even tried using the array for SendClientMessage, and it worked as it should, printed everything out normally. But this is still happening.



That is an image of me selecting each list item, one by one, from the top of the list.

Here is the bits of code I changed.

pawn Код:
if(dialogid == RADIO_GENRE_ROCK)
    {
        if(!response)
        {
            DisplayMain(playerid);
            return 1;
        }
        foreach(Player, i)
        {
            new veh = GetPlayerVehicleID(playerid);
            if(GetPlayerVehicleID(i) == veh)
            {
                PlayAudioStreamForPlayer(i, RockStations[listitem][1][60]); //60 being the size of the string.
                SetPVarInt(i, "Streaming", 1);
            }
        }
    }
pawn Код:
new RockStations [] [] [] =
{
    {"181.fm - The Buzz!", "http://yp.shoutcast.com/sbin/tunein-station.pls?id=37586"},
    {"Radio Paradise", "http://yp.shoutcast.com/sbin/tunein-station.pls?id=785339"},
    {"181.fm - Awesome 80's", "http://yp.shoutcast.com/sbin/tunein-station.pls?id=785339"},
    {"idobi Radio", "http://yp.shoutcast.com/sbin/tunein-station.pls?id=914897"},
    {"Star.fm - Maximum Rock!", "http://yp.shoutcast.com/sbin/tunein-station.pls?id=108588"},
    {"181.fm - 90's Alternative", "http://yp.shoutcast.com/sbin/tunein-station.pls?id=1034265"},
    {"181.fm - Hard Rock Heaven", "http://yp.shoutcast.com/sbin/tunein-station.pls?id=106750"}
};
If anyone could provide me with some insight... I'd be so thankful! I have spent quite a deal of time writing this system as a whole, and this tiny problem is making everything seem impossible!

Thank you!

EDIT: Could I maybe switch out the order of the array and have the names second?
Reply
#4

Read my new post
Reply
#5

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
I'm pretty sure it should be a 2D array and look like this man....

PlayAudioStreamForPlayer(i, RockStations[listitem]);

This would just use the second character only as the string
PlayAudioStreamForPlayer(i, RockStations[listitem][1]);

ex.

{"181.fm - The Buzz!", "http://yp.shoutcast.com/sbin/tunein-station.pls?id=37586"},

Would use "8" as the string.
I know this wouldn't work because the array dimensions wouldn't match up.

It'd give me an error saying something like... "dimensions of array don't match"

I've seen that error before after I had tried something similar if not the same.

Any other kind of idea? I'll still give that bit a go, but I am almost certain it wouldn't work out.
Reply
#6

Ahhh I see... my bad... I was reading it as a single string derp try doing it like this

Note: Adjust MAX_STATION_NAME and MAX_STATION_LINK to appropriate sizes.

pawn Код:
#define MAX_STATION_NAME 128
#define MAX_STATION_LINK 256

enum StationInfo {
    StationName[MAX_STATION_NAME],
    StationLink[MAX_STATION_LINK],
}

new RockStations [] [StationInfo] =
{
    {"181.fm - The Buzz!", "http://yp.shoutcast.com/sbin/tunein-station.pls?id=37586"},
    {"Radio Paradise", "http://yp.shoutcast.com/sbin/tunein-station.pls?id=785339"},
    {"181.fm - Awesome 80's", "http://yp.shoutcast.com/sbin/tunein-station.pls?id=785339"},
    {"idobi Radio", "http://yp.shoutcast.com/sbin/tunein-station.pls?id=914897"},
    {"Star.fm - Maximum Rock!", "http://yp.shoutcast.com/sbin/tunein-station.pls?id=108588"},
    {"181.fm - 90's Alternative", "http://yp.shoutcast.com/sbin/tunein-station.pls?id=1034265"},
    {"181.fm - Hard Rock Heaven", "http://yp.shoutcast.com/sbin/tunein-station.pls?id=106750"}
};

PlayAudioStreamForPlayer(i, RockStations[listitem][StationLink]); //60 being the size of the string.
That should work for you now sorry about that I'm pretty tired and missed that at first glance.
Reply
#7

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
Ahhh I see... my bad... I was reading it as a single string derp try doing it like this

Note: Adjust MAX_STATION_NAME and MAX_STATION_LINK to appropriate sizes.

pawn Код:
#define MAX_STATION_NAME 128
#define MAX_STATION_LINK 256

enum StationInfo {
    StationName[MAX_STATION_NAME],
    StationLink[MAX_STATION_LINK],
}

new RockStations [] [StationInfo] =
{
    {"181.fm - The Buzz!", "http://yp.shoutcast.com/sbin/tunein-station.pls?id=37586"},
    {"Radio Paradise", "http://yp.shoutcast.com/sbin/tunein-station.pls?id=785339"},
    {"181.fm - Awesome 80's", "http://yp.shoutcast.com/sbin/tunein-station.pls?id=785339"},
    {"idobi Radio", "http://yp.shoutcast.com/sbin/tunein-station.pls?id=914897"},
    {"Star.fm - Maximum Rock!", "http://yp.shoutcast.com/sbin/tunein-station.pls?id=108588"},
    {"181.fm - 90's Alternative", "http://yp.shoutcast.com/sbin/tunein-station.pls?id=1034265"},
    {"181.fm - Hard Rock Heaven", "http://yp.shoutcast.com/sbin/tunein-station.pls?id=106750"}
};

PlayAudioStreamForPlayer(i, RockStations[listitem][StationLink]); //60 being the size of the string.
That should work for you now sorry about that I'm pretty tired and missed that at first glance.
Oh man... YOU... are a life saver...

Thank you so much! I don't know what I would've done without your help!
That is absolutely a well deserved +rep!

Really, thank you so much!
Reply
#8

Hey no problem, sorry I derped on the first response but now you have your solution so no worries.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)