Comments inside strings
#1

Is it possible to put comments inside strings? I want to make a list of models in a string like so:

pawn Код:
new gVehModel_Motorbike[] = {
462, // Faggio
581, // BF-400
461, // PCJ-600
521, // FCR-900
463, // Freeway
586 // Wayfarer
Obviously that's not a string but an array, I'd like to make it a string without losing the coments so I know which vehicle is which.
Is there a way apart from using strcat? I'd really like to initialize the string as it is as it's never going to be changed.

I tried this but it turned it all in to a string:
pawn Код:
new gVehModel_Motorbike[] = "\
462, /* Faggio*/\
581, /* BF-400*/\
461, /* PCJ-600*/\
521, /* FCR-900*/\
463, /* Freeway*/\
586 \* Wayfarer*/\
"
;
:<
Reply
#2

Why would you want to do that in the first place?
Reply
#3

Quote:
Originally Posted by MP2
Посмотреть сообщение
Is it possible to put comments inside strings? I want to make a list of models in a string like so:

pawn Код:
new gVehModel_Motorbike[] = {
462, // Faggio
581, // BF-400
461, // PCJ-600
521, // FCR-900
463, // Freeway
586 // Wayfarer
Obviously that's not a string but an array, I'd like to make it a string without losing the coments so I know which vehicle is which.
Is there a way?
Strings are arrays.

pawn Код:
new string[] = "Hello";
new string2[] = {'H', 'E', 'L', 'L', 'O', '\0'};
^Same thing btw.

Erm, to answer your question. If you mean something like this:

pawn Код:
new string[] = "Hello //Comment"
Nope, when wrapped EVERYTHING is part of the string, with the exclusion of character sequences such as the null terminator and newline but you get what i mean.
Reply
#4

Quote:
Originally Posted by Vince
Посмотреть сообщение
Why would you want to do that in the first place?
Because if I come back to this in the future:

"4 53 1325435 325 454 53541 134 3143" (pretend it's real model ids) and want to remove for example, a Buffalo, instead of just looking for a comment saying // Buffalo I have to mess around finding the model for the Buffalo.

I actually have two options here..

Option 1: Have a string of sporty vehicles and split that in to an array of models, like others.
Option 2: Have an array of models and just reference that when I need it.

Option 2 would be better, but the problem is I'd have to make two separate systems if I go with option 2, so I lazily chose this.

@Gh05t_: I know strings are arrays. The context I meant was one was an array of models, one was a string of models.
Reply
#5

Код:
new Array[][] = {
	{ 400, "Hello" },
	{ 411, "Hi, samp." }
};
And results...
Quote:

[19:45:59] One: 400
[19:45:59] Two: Hello
[19:45:59] ----------------------------------------------------
[19:45:59] One: 411
[19:45:59] Two: Hi, samp.

Код:
	printf("One: %d", Array[0][0]);
	printf("Two: %s", Array[0][1]);
	print("----------------------------------------------------");
	printf("One: %d", Array[1][0]);
	printf("Two: %s", Array[1][1]);
Reply
#6

What..? Wasting memory for a comment? What's the point in that?

I'm probably going to just use an array instead of a string. It'd save memory and untimately be easier to handle. It just means a bit of work for me.
Reply
#7

Sort them using an enumeration.

pawn Код:
#include <a_samp>

enum { One, Two, Three, Four };

new Array[] = { 1, 2, 3, 4 };

main ()
{
    printf("%d", Array[Three]);
}
Reply
#8

EDIT: Too slow
Reply
#9

Because I'm lazy :<
Reply
#10

Quote:
Originally Posted by MP2
Посмотреть сообщение
Because I'm lazy :<
Nope, your just confused. Don't ignore what I've said. If your using an array to sort values, you can use an enumeration as reference to these values.
Reply
#11

Pawn supports static string concatenation, so you can do it like this:

pawn Код:
//note:
"string1""string2" == "string1string2"

new gVehModel_Motorbike[] = "\
462, "
/* Faggio*/"\
581, "
/* BF-400*/"\
461, "
/* PCJ-600*/"\
521, "
/* FCR-900*/"\
463, "
/* Freeway*/"\
586 "
/* Wayfarer*/"\
"
;
Though I really dont see why you should do that. Saving ids as strings takes more ram, and parsing them back to integers to use them takes more cpu.
Reply
#12

Quote:
Originally Posted by Gh05t_
Посмотреть сообщение
Nope, your just confused. Don't ignore what I've said. If your using an array to sort values, you can use an enumeration as reference to these values.
No, you're confused. I don't need to sort anything, I was just asking about comments.

Thanks Mauzen, but I'm going to use an array instead. Makes more sense.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)