Why does this not work? Simple Text
#1

pawn Код:
ObjectInfo[i][oName] = example;
When doing it like this I am unable to save the text to a file or collect it and use it else where for example

pawn Код:
Object ID %d's Name is %s i, ObjectInfo[i][oName]
How can I achieve what I'm trying to do?
Reply
#2

Don't use assignment (=) for copying a string to another. Use strcat instead.

pawn Код:
strcat((ObjectInfo[i][oName][0] = '\0', ObjectInfo[i][oName]), example, SIZE_HERE);
Change the 'SIZE_HERE' with the size the index oName have in the enum.
For example, if it's:
pawn Код:
oName[32],
then change 'SIZE_HERE' to 32.
Reply
#3

Quote:
Originally Posted by Phil_Cutcliffe
Посмотреть сообщение
pawn Код:
ObjectInfo[i][oName] = example;
When doing it like this I am unable to save the text to a file or collect it and use it else where for example

pawn Код:
Object ID %d's Name is %s i, ObjectInfo[i][oName]
How can I achieve what I'm trying to do?
I am not so sure but I guess you can try using

pawn Код:
format(ObjectInfo[i][oName], 100, example);
Let me explain if you didn't get it (not that good at explaining...) on that line it's like setting the name to that var/enum as the name is a string right? %s? (hope you can follow lol) so technically you would use format

the "100" is the size of the characters used for example when you "new string[120];" you have made space for 119 chars

The "example" part might not work as "example" must also be formatted like this

pawn Код:
format(example, 100, "example");
Now you set a string for 'example' and you set that string for the object name... (I failed I think)

But instead I would advise using (if you want to save what the player types)
pawn Код:
format(ObjectInfo[i][oName], 100, "your text for the object name here.");
If you didn't quite get it, post something of the code and few details of what you want to do.. Like edit the name, save name/load name such things.
Reply
#4

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Don't use assignment (=) for copying a string to another. Use strcat instead.

pawn Код:
strcat((ObjectInfo[i][oName][0] = '\0', ObjectInfo[i][oName]), example, SIZE_HERE);
Change the 'SIZE_HERE' with the size the index oName have in the enum.
For example, if it's:
pawn Код:
oName[32],
then change 'SIZE_HERE' to 32.
I'm just trying to simply write a name for each object

ObjectName = name;

And save that to the file and else where in my script like

/editfurni will show a dialog and show Object ID %d Name %s object, ObjectName

Are you telling me to specify a simple peace of text I have to do that for every single one? Where as if I wanted to just specify ObjectNumber = 1; it works just fine.. ?
Reply
#5

You cannot copy strings like that:
pawn Код:
string1 = string2;
You should use another method such as strcat, memcpy, strins, format (slowest way).
Reply
#6

Yes, you can copy strings like that, under the condition that the number of dimensions is the same and that the size of the array on the left is equal or greater than the size of the array on the right.

pawn Код:
new test1[] = "hello world";
new test2[12];

test2 = test1;
printf("test2 = \"%s\"", test2);
In this particular case, however, the number of dimensions isn't the same so direct assignment does not work.
Reply
#7

Ok I think everyone is thinking well outside of the box or maybe I'm just not seeing it lol.

Here's what I'm trying to do.

A player types /furniture and it brings up a menu of furniture to choose from

When a player clicks on an item it will create the item setting a few things as follows for example

ObjectInfo[i][oX] = 0.0;
ObjectInfo[i][oY] = 0.0;
ObjectInfo[i][oZ] = 0.0;
ObjectInfo[i][oChair] = 1;
ObjectInfo[i][oName] = chair_01;

chair_01 is simply just text that I have written. It is not gathered from any where else. I am just simply setting the name to chair_01.

The reason for this is the player can then use /furniedit which brings up a menu of all the furniture in their house.

The check is done for(new object = 0; object < sizeof(ObjectInfo) object++)
This shows Object ID &d (54) Name %s (chair_01) (the number which is "object" and the name which is now a string ObjectInfo[object][Name])

Are you guys following me? I'm not trying to for example do this

/setname "id" "namehere"

new id = first bit of text

new name = second bit of text
Reply
#8

Ok I think I'm on the right track now after having some sleep

pawn Код:
strpack(ObjectInfo[i][oName], "mrk_seating1", 20);
This however just gets _t1

How do I sort that? xD

EDIT: Fixed it finally lol

pawn Код:
strins(ObjectInfo[i][oName], "mrk_seating1", 0, 20);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)