Author Topic: Correctly searching a string?[Solved]  (Read 1136 times)

Okay, so I feel like there might actually be a method for this, and what I'm doing is way overboard, if not then I guess I still need help.

Anywho.

Here's what my issue/need is:

Let's say the data is "Tree Flower Weed"
I send this to the function "getPlant(%data)"

I need getPlant to return 1/true if it finds the word "Plant", if not return 0/false.
This means that plant can be located anywhere in the data string sent, but it needs to be found anyways.

I tried using a for loop with getword and all that jazz but I couldn't get it to work correctly.
« Last Edit: October 27, 2012, 11:53:03 AM by ¥ola »



To be more exact than an entire reference post, what you're looking for is strPos or striPos.

strPos(%haystack, %needle, %offset) - Case sensitive search, will return position in haystack that needle is or -1 if it is not there
striPos(%haystack, %needle, %offset) - Case insensitive search, will return position in haystack that needle is or -1 if it is not there

Code: [Select]
function isItThere(%haystack, %needle)
{
if(striPos(%haystack, %needle) >= 0)
return 1;
return 0;
}

To be more exact than an entire reference post, what you're looking for is strPos or striPos.

strPos(%haystack, %needle, %offset) - Case sensitive search, will return position in haystack that needle is or -1 if it is not there
striPos(%haystack, %needle, %offset) - Case insensitive search, will return position in haystack that needle is or -1 if it is not there

Code: [Select]
function isItThere(%haystack, %needle)
{
if(striPos(%haystack, %needle) >= 0)
return 1;
return 0;
}

I ended up using strStr, and it works just fine

I ended up using strStr, and it works just fine
You probably want to switch to striPos, strStr is case-sensitive.

Unless that won't cause problems in your script.

You probably want to switch to striPos, strStr is case-sensitive.

Unless that won't cause problems in your script.
I actually need case sensitivity, so it worked out well I'm assuming

You probably want to switch to striPos, strStr is case-sensitive.

Unless that won't cause problems in your script.
Wtf Torque doesn't have stristr


he said stripos
not stristr
yeah, he was probably referring to how silly it is that striStr doesn't exist

Just a quick question about global variables.

When you define a global variable in the script itself, upon starting up the script it sets itself to that defined variable.

When you edit it, and restart it it resets the variable.

I want to be able to edit my variable via out of game, and using a function ingame, and have it save and upon restart use the last defined version.

Any possible way to do this?

okay that was worded so horriblynot so well
i can't understand any of it

"upon starting up the script it sets itself to that defined variable."
wh-
w-

how does the script set itself to a variable?
« Last Edit: October 23, 2012, 06:27:03 PM by Ipquarx »

Just a quick question about global variables.

When you define a global variable in the script itself, upon starting up the script it sets itself to that defined variable.

When you edit it, and restart it it resets the variable.

I want to be able to edit my variable via out of game, and using a function ingame, and have it save and upon restart use the last defined version.

Any possible way to do this?
if you export it (export("$moose", "config/moose.cs"); or something, you can also use wildcards if you have an array or lots of variables or something; "$moose*" will export $mooseA, $moose::situps, $moosewaluigibananapants, etc.) at some point (eg upon quitting the game), and then execute the file upon starting the game, that would work.
then you could also edit the .cs file when the game isn't running.

this is how all global variables that remain persistent across multiple simulations do so unless they're wizards or something

Or you use $Pref::Server:blah and it will auto-save to config/server/prefs.cs

Or you use $Pref::Server:blah and it will auto-save to config/server/prefs.cs
Yes.

For organization, though, someone may want to not do that.