Printing out something from an enum
#1

Hey guys, been trying to use enums for database storing purposes, anywho here's the enum(some of it):

PHP код:
enum biz_Lists
{
    
biz_T,
    
biz_N[50],
}
new 
BizTypeList[][biz_Lists] = {
    {
BUSINESS_TYPE_BANK"Bank"},
    {
BUSINESS_TYPE_247"Grocery Store"}, 
and here are the code lines for the formatting a string to the variable:
PHP код:
    BizTypeList[biz_T] = bizType;
    
format(iStrsizeof(iStr), "%s"BizTypeList[biz_T][biz_N]); 
tho it doesn't really work. Been trying to shift things around and got shitloads of errors.
would love for some help! Thanks :>
Reply
#2

Reply
#3

Quote:
Originally Posted by Amit1998
Посмотреть сообщение
Hey guys, been trying to use enums for database storing purposes, anywho here's the enum(some of it):

PHP код:
enum biz_Lists
{
    
biz_T,
    
biz_N[50],
}
new 
BizTypeList[][biz_Lists] = {
    {
BUSINESS_TYPE_BANK"Bank"},
    {
BUSINESS_TYPE_247"Grocery Store"}, 
and here are the code lines for the formatting a string to the variable:
PHP код:
    BizTypeList[biz_T] = bizType;
    
format(iStrsizeof(iStr), "%s"BizTypeList[biz_T][biz_N]); 
tho it doesn't really work. Been trying to shift things around and got shitloads of errors.
would love for some help! Thanks :>
This a wrong way to use list. I don't know how to do what you want. I understand but I don't know. Maybe someone can give the solution.. :/

PHP код:
#include <a_samp>
/*enum biz_Lists
{
    biz_T,
    biz_N[50],
}*/
enum bizType
{
    
BUSINESS_TYPE_BANK,
    
BUSINESS_TYPE_247
}
new 
BizTypeList[2][] =
{
    
"Bank",
    
"Grocery Store"
};
new 
biz[bizType];
main()
{
    
printf("%s %s"BizTypeList[0][0], BizTypeList[1][0]);

Reply
#4

The problem is you need an index for that.

For example:

PHP код:
enum biz_Lists 

    
biz_T
    
biz_N[50], 

new 
BizTypeList[10][biz_Lists]; //We make this to 10...so u can max create 10 Biz (index: 0-9)
new biz_index//We will need this to accsess everytime the Variable
//To Create one Biz we do sth like this
if(biz_index >= sizeof(BizTypeList)) return SendClientMessage(playerid,-1,"Biz is full!"); //PS: sizeof(BizTypeList) = 10
BizTypeList[biz_index][biz_T] = BUSINESS_TYPE_BANK//For example
format(BizTypeList[biz_index][biz_N],50"Bank"); //So we set this
biz_index++; //we count this up...so the next one we insert is an index above
/*
 To read this stuff out...you need an index
 In my example the Bank is at index 0. Cause the Variable biz_index was zero.
*/
//So we do sth like this:
new string[50],type;
format(string,50,BizTypeList[0][biz_N]); //Now string equals Bank
type BizTypeList[0][biz_T]; //And type equals BUSINESS_TYPE_BANK 
So i hope you see..the index is the key
Reply
#5

Quote:
Originally Posted by Kaliber
Посмотреть сообщение
The problem is you need an index for that.

For example:

PHP код:
enum biz_Lists 

    
biz_T
    
biz_N[50], 

new 
BizTypeList[10][biz_Lists]; //We make this to 10...so u can max create 10 Biz (index: 0-9)
new biz_index//We will need this to accsess everytime the Variable
//To Create one Biz we do sth like this
if(biz_index >= sizeof(BizTypeList)) return SendClientMessage(playerid,-1,"Biz is full!"); //PS: sizeof(BizTypeList) = 10
BizTypeList[biz_index][biz_T] = BUSINESS_TYPE_BANK//For example
format(BizTypeList[biz_index][biz_N],50"Bank"); //So we set this
biz_index++; //we count this up...so the next one we insert is an index above
/*
 To read this stuff out...you need an index
 In my example the Bank is at index 0. Cause the Variable biz_index was zero.
*/
//So we do sth like this:
new string[50],type;
format(string,50,BizTypeList[0][biz_N]); //Now string equals Bank
type BizTypeList[0][biz_T]; //And type equals BUSINESS_TYPE_BANK 
So i hope you see..the index is the key

How come this one doesn't work?
PHP код:
COMMAND:checkbiztype(playeridparams[])
{
new 
iBiz;
if( 
sscanf params"d"iBiz)) return SCP(playerid"[BizID]");
new 
BizTypeID BusinessInfo[iBiz][bType];
new 
iTypeName BizTypeList[BizTypeID][biz_N];
format(iStrsizeof(iStr), "String: %s || Int: %d"iTypeNameiTypeName);
SendClientMessage(playeridCOLOR_WHITEiStr);
return 
1;

at first I retrieve the biz type ID, and then I adderss the ID's name from it's enum..
Reply
#6

//Edit:
Oh god...now i see what you wanna do...
Just make it like this:

PHP код:
COMMAND:checkbiztype(playeridparams[]) 
{
    new 
index,string[128]; //Use this..you should avoid global strings...
    
if( sscanf params"d"index)) return SCP(playerid"[BizID]"); 
    if(
index || index >= sizeof(BusinessInfo)) return SCP(playerid,"Index out of Bounds!"); 
    
format(stringsizeof(string), "String: %s || Int: %d"getBizName(BusinessInfo[index][bType]),  BusinessInfo[index][bType]); 
    
SendClientMessage(playeridCOLOR_WHITEstring); 
    return 
1
}
stock getBizName(index)
{
    new 
name[50];
    switch(
index)
    {
        case 
BUSINESS_TYPE_BANKname="Bank";
        case 
BUSINESS_TYPE_247name="Grocery Store";
    }
    return 
name;

Reply
#7

Quote:
Originally Posted by Kaliber
Посмотреть сообщение
//Edit:
Oh god...now i see what you wanna do...
Just make it like this:

PHP код:
COMMAND:checkbiztype(playeridparams[]) 
{
    new 
index,string[128]; //Use this..you should avoid global strings...
    
if( sscanf params"d"index)) return SCP(playerid"[BizID]"); 
    if(
index || index >= sizeof(BusinessInfo)) return SCP(playerid,"Index out of Bounds!"); 
    
format(stringsizeof(string), "String: %s || Int: %d"getBizName(BusinessInfo[index][bType]),  BusinessInfo[index][bType]); 
    
SendClientMessage(playeridCOLOR_WHITEstring); 
    return 
1
}
stock getBizName(index)
{
    new 
name[50];
    switch(
index)
    {
        case 
BUSINESS_TYPE_BANKname="Bank";
        case 
BUSINESS_TYPE_247name="Grocery Store";
    }
    return 
name;

Hum, why isn't this working then?

PHP код:
stock CreateBusiness(bizOwner[], bizTypeFloat:bizXFloat:bizYFloat:bizZInteriorVirtualWorld)
{
// Missing codelines ---> bizType is an int which refers to the ID of a biz type, which is used to create business from the BizTypeList..
    
new iTypeName BizTypeList[bizType][biz_N];
    
mysql_format(MySQLPipelineiQuerysizeof(iQuery), "INSERT INTO `businessinfo` (`ID`, `Owner`, `Type`, `TypeName`, `X`, `Y`, `Z`, `CompsFlag`, `Interior`, `VirtualWorld`, `Street`) VALUES (%d, '%e', %d, '%e', %f, %f, %f, %d, %d, %d, '%e')"businessidbizOwnerbizTypeiTypeNamebizXbizYbizZcompsFInteriorVirtualWorldzone);
    
mysql_tquery(MySQLPipelineiQuery); 
Reply
#8

You only need the strings then and the type is the index of the array:
PHP код:
// global:
new const BizTypeList[][] = 
{
    
"Bank",
    
"Grocery Store",
    
"Casino",
    
"Gas Station",
    
"Hardware Store",
    
"Night club",
    
"Pub",
    
"Strip Club",
    
"Gun Store",
    
"Pizza Stack",
    
"Burger Shot",
    
"Cluckin' Bell",
    
"Cafe",
    
"Clothes Store",
    
"Restaurant",
    
"Pay 'N' Spray",
    
"Drug Factory",
    
"Government Tax Income",
    
"Refinary Income",
    
"Airport",
    
"Taxi Station",
    
"Vehicle Rent",
    
"Driver Business",
    
"Stadium Business",
    
"Paintball",
    
"Advertisement Tower",
    
"Phone Provider",
    
"Vehicle Exports",
    
"Drug Store",
    
"Bike Dealership",
    
"Heavy Dealership",
    
"Car Dealership",
    
"Luxus Dealership",
    
"Noobie Dealership",
    
"Air Dealership",
    
"Boat Dealership",
    
"Job Dealership",
    
"Wheel Mod Shop",
    
"Toy Store",
    
"Appartment Complex",
    
"Hotel",
    
"Vehicle Register"

Have a variable that indicates what type is each biz and then:
pawn Код:
BizTypeList[biz_type_here]
Reply
#9

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
You only need the strings then and the type is the index of the array:
PHP код:
// global:
new const BizTypeList[][] = 
{
    
"Bank",
    
"Grocery Store",
    
"Casino",
    
"Gas Station",
    
"Hardware Store",
    
"Night club",
    
"Pub",
    
"Strip Club",
    
"Gun Store",
    
"Pizza Stack",
    
"Burger Shot",
    
"Cluckin' Bell",
    
"Cafe",
    
"Clothes Store",
    
"Restaurant",
    
"Pay 'N' Spray",
    
"Drug Factory",
    
"Government Tax Income",
    
"Refinary Income",
    
"Airport",
    
"Taxi Station",
    
"Vehicle Rent",
    
"Driver Business",
    
"Stadium Business",
    
"Paintball",
    
"Advertisement Tower",
    
"Phone Provider",
    
"Vehicle Exports",
    
"Drug Store",
    
"Bike Dealership",
    
"Heavy Dealership",
    
"Car Dealership",
    
"Luxus Dealership",
    
"Noobie Dealership",
    
"Air Dealership",
    
"Boat Dealership",
    
"Job Dealership",
    
"Wheel Mod Shop",
    
"Toy Store",
    
"Appartment Complex",
    
"Hotel",
    
"Vehicle Register"

Have a variable that indicates what type is each biz and then:
pawn Код:
BizTypeList[biz_type_here]


Tho I still need the Businesses_Type_Bank(etc) defines as I'm using these in the biz system. I just need a function to extract the string from the enum :S
Reply
#10

Quote:
Originally Posted by Amit1998
Посмотреть сообщение
Tho I still need the Businesses_Type_Bank(etc) defines as I'm using these in the biz system. I just need a function to extract the string from the enum :S
Keep those and instead of 'a function to extract' have a variable as I mentioned earlier to know the type of each biz. Then using that type as index in BizTypeList will give the name.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)