How to specify mutiple strings in text value

Started by Kelvinvenema, Feb 05, 2020, 05:44 PM

Previous topic - Next topic

Kelvinvenema

Hello guys sorry to bother you guys again, I really want to know how I can script with using "text"

I still have one question, how could I add multiple strings in text I know how I can use it in if statements, but the same way ain't
working when using text how can I combine this

 if (text == "a") && (text == "o")

how can I combine them to work fine it doesn't work if I do this:

if (text == "a || o ")
// Do function

NicusorN5

#1
You mean something like strstr(const char*,const char*) in C++?

http://www.cplusplus.com/reference/cstring/strstr/

If you mean checking if the user's text is either 'a' or 'o' use
if((text == "a") || (text == "o")
Explanation: the || is the logic OR operator.

Kelvinvenema

Quote from: Athanatos on Feb 05, 2020, 06:18 PMYou mean something like strstr(const char*,const char*) in C++?

http://www.cplusplus.com/reference/cstring/strstr/

If you mean checking if the user's text is either 'a' or 'o' use
if((text == "a") || (text == "o")
Explanation: the || is the logic OR operator.

Thanks, for the explanation I appreciate it!
Both are good to know so I could interpret them,
but there isn't any other way to make them smaller expect using functions?
if((text == "a") || (text == "o")
or
if((text == "a") && (text == "o")
 to make them smaller for example:
if (player.Skin == 5 || 6 || 7)
it's pretty clear what it does isn't there a easier to make it smaller?
or else it would probally be pretty painfull for my newsystem, my new system is suppost to filter out characters like. "! || @ || # || $ || % || ^ || & || * || ( || ) " and if I made a lot of (text == "character") it would take me some time to finish it
is there a way to make it if (text == "@ or # or $") or if (text == "@ && # && $)
or isn't that possible
anyways thanks for explaining it so far!

NicusorN5

#3
Not really. Functions are the single way to do so. I dont even think any proper language allows you to use if statements like specified. (except JavaScript because it's gay? lol ) And np.

And I think squirreil allows String.Replace(string). Didnt read the documentation. I'll post a link there : <todo insert link , but I want to sleep, posting on forums and game developing at 11:12 PM is nice.>

Kelvinvenema

#4
Quote from: Athanatos on Feb 05, 2020, 09:07 PMNot really. Functions are the single way to do so. I dont even think any proper language allows you to use if statements like specified. (except JavaScript because it's gay? lol ) And np.

And I think squirreil allows String.Replace(string). Didn't read the documentation. I'll post a link there : <todo insert link , but I want to sleep, posting on forums and game developing at 11:12 PM is nice.>

Yeah, I never looked at Java, because my mainfocus is especially on SQL and squirrel language, so I don't want to learn multiple languages at once.
So am i better of creating dedicated functions?

NicusorN5


habi

#6
function P(t,...)
{
foreach(val in vargv)
{
if(t==val)return 1;
}
return 0;
}

local t=4;
if(P(t,1,2,3))print("yes");

Kelvinvenema

Quote from: habi on Feb 07, 2020, 02:40 AMfunction O(t,a,...)
{
foreach(val in vargv)
{
if(t==val)return 1;
}
return 0;
}

local t=4;
if(O(t,1,2,3))print("yes");

how could I get it to work in a command it keeps saying that index t doesn't exist or should I make local t = text; ?

habi

Use the function like
O(text, "@","$")Again   O(player.Skin, 5,6,7)   if it is player.skin

Kelvinvenema

Quote from: habi on Feb 08, 2020, 12:31 PMUse the function like
O(text, "@","$")Again   O(player.Skin, 5,6,7)   if it is player.skin


I appreciate you for helping me, but it still doesn't output the output but it shows some errors this is what I typed pretty simple command.


else if (cmd == "antext")
{
if(O(text, "@","$"))
{
print("no");
}
}

my error is:

AN ERROR HAS OCCURED [attempt to call 'integer']

CALLSTACK
*FUNCTION [onPlayerCommand()] scripts/Command.nut line [955]

LOCALS
[params] NULL
[text] "$"
[cmd] "antext"
[arguments] "$"
[command] "antext"
[player] INSTANCE
[this] TABLE


I tried everything to get it to work changing the name of variables renaming the function completely overdo the function, but nothing seems to work.
can you tell me if I miss another function to get it to work or what did I do wrong?

habi

#10
hey kevin, i tried your code and it showed no errors.

did you mistake O for 0 ?

also next time specify which is the error line.

Kelvinvenema

Quote from: habi on Feb 09, 2020, 01:55 PMhey kevin, i tried your code and it showed no errors.

did you mistake O for 0 ?

also next time specify which is the error line.

it could be, but if I type o = 0 in my code and I have no clue how I can change that.
and it could be that you may have some other functions that let your code work differently from mine.

habi

#12
which is the line 955 ?
i updated the function

Kelvinvenema

Quote from: habi on Feb 12, 2020, 01:46 PMwhich is the line 955 ?
i updated the function

Yes, it is it also doesn't work for you now?

habi

it works fine. There was a small parameter problem which I fixed