I’m setting up a placeable store where the PC can choose from a few different equipment to purchase for their lab. From a conversation, they will choose from a list of placeables, some with a few different kinds. Each option will spawn as a placeable sample so they can get a look at it and choose to purchase or not. With each new selection, the first will need to be destroyed first, no matter what it is. At present, there are 10, each one has a tag with the first 10 characters the same, followed by 01 to 10.
*
Here’s the question, can I set a variable to look at the first 10 characters of the string, not care about the last 2 (treat them as wildcards), then destroy any placeable where the tag matches the first 10 characters as long as the search returns valid (there exists something to destroy)? How would I code something like that?
*
The creation part will be easy and specific to the res refs, I know that part. A new short script for each option, though, I suppose there is a way to do a keyboard entry to, though that may prove more trouble than it’s worth in this case.
This is what I’ve got so far, I’m close (it compiles) but it hangs and croaks with the following: “Script sample_port_1, OID: 80000258, Tag:Rodon, ERROR: TOO MANY INSTRUCTIONS”. It could be that something is wrong with my loop. Or maybe it is searching the entire module rather than just the current area. Current area is all I need checked.
void main()
{
string sSample = "BMG_SAMPLE"; //Exact match we want
object oSample = GetNearestObject(OBJECT_TYPE_PLACEABLE);
string sTag = GetTag(oSample);
string sCheck = GetSubString(sTag, 0, 10); //Get first 10 characters of nearest object
if (sCheck != sSample) //Compare first 10 characters of nearest object with our string constant
return;
int i = 1;
while (oSample!= OBJECT_INVALID)
{
DestroyObject(oSample);
i++;
//oSample = GetNearestObject(OBJECT_TYPE_PLACEABLE);
}
}
Try the function GetStringLeft(string, int)
(read its description in the Lexicon) for getting the first X number of characters in a string. For example -
sTestMe = GetStringLeft(sYourString, 10);
if(sTestMe == sPattern)
//destroy whatever here
TR
Okay folks, nevermind. After extensive study of the Lexicon, I have figured it out. It does EXACTLY what I want. Time to move on to the next part of the script, the easy part.
void main()
{
object oArea = OBJECT_SELF;
string sSample = “BMG_SAMPLE”; //Exact match we want
object oSample = GetFirstObjectInArea(oArea);
string sTag = GetTag(oSample);
string sCheck = GetSubString(sTag, 0, 10); //Get first 10 characters of nearest object
while (GetIsObjectValid(oSample))
{
if (sCheck == sSample) //Compare first 10 characters of nearest object with our string constant
{
//SpeakString(sTag); Error Checking
//SpeakString(sCheck); Error Checking
DestroyObject(oSample);
}
oSample = GetNextObjectInArea(oArea);
sTag = GetTag(oSample);
sCheck = GetSubString(sTag, 0, 10);
//SpeakString(sCheck);
}
}
FWIW
does exactly the same as
With the advantage of being more obvious in what it is doing and uses one less parameter.
TR
Not to mention, that “substring (s,0,10)” are 11 chars
Nah, getsubstring in nwscript takes a count as the third parameter…