Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   defining script from string (https://forums.graalonline.com/forums/showthread.php?t=24522)

btedji 02-25-2002 03:23 AM

defining script from string
 
Ok heres the deal:

1) I set a string like this:

setstring client.Test,##v(this.test)##s(client.Test2);

2) It looks like this in the flag list:

client.Test=#v(this.test)#s(client.Test2)

3) The variable this.test has a value of lets say 5
and string client.Test2=blah

4) I want this code to make it show 5blah
not #v(this.test)#s(client.Test2):

setplayerprop #c,#s(client.Test);

How can I get that to work right, and I have to have it in the string like that so that it will show the current value in the variables and strings

Goboom 02-25-2002 03:28 AM

are you talking about something like this????
NPC Code:

client.test=strtofloat(#s(test));
client.test++;
setstring test,#v(client.test);


didnt understad question that well

Faheria_GP2 02-25-2002 03:34 AM

he wants message codes to be parsed for message codes...

like if #c contains the chat "#s(***)", #c would read the value of string ***, not literally "#s(***), origianally it was like this, but it caused issues back in 1.31, so message codes no longer act like this

btedji 02-25-2002 03:36 AM

like this

NPC Code:

if(playerenters){
timeout=0.05
this.test=5;
setstring client.test,##v(this.test);
}

if(timeout){
timeout=0.05;
this.test++;
setplayerprop #c,#s(client.test);
}




the players text should always show the current value of this.test

dont know how to get that to work right

Faheria_GP2 02-25-2002 03:50 AM

you cant put a message code in a message code

end of story

close thread

btedji 02-25-2002 03:52 AM

Quote:

Originally posted by Faheria_GP2
you cant put a message code in a message code

end of story

close thread

Nested message codes are allowed, just if message codes from strings cant be used inside other message codes, then it should be a future improvement

Faheria_GP2 02-25-2002 03:56 AM

Quote:

Originally posted by btedji


Nested message codes are allowed, just if message codes from strings cant be used inside other message codes, then it should be a future improvement

nested mesage codes are allowed?

so when #c is #f, then #c is door.gif? no, people were abusing it, so it was "fixed" in version 1.38 or so

joseyisleet 02-25-2002 05:44 AM

-=Josey=-
I forgot how to do this whenever I left and came back, but a friend helped me out again.

NPC Code:

if (created||playerenters){
setstring client.test,5;
timeout=.05;
}
if (timeout){
message # strtofloat(#s(client.test));
timeout=.05;
}


joseyisleet 02-25-2002 05:46 AM

-=Josey=-
Oh yeah, use something like :
setstring client.test, strtofloat(#s(client.test))+1;

I do believe that should work.

nyghtGT 02-25-2002 06:00 AM

Quote:

Originally posted by joseyisleet
-=Josey=-
Oh yeah, use something like :
setstring client.test, strtofloat(#s(client.test))+1;

I do believe that should work.

setstring client.test, #v(strtofloat(#s(client.test))+1);

:D

btedji 02-25-2002 08:20 PM

Bah! Guess i'll have to change my script, oh well :(

Admins 02-25-2002 09:59 PM

It would be possible to support it
(the message code stuff is currently parsed
at runtime, but only the first time it is seen).
Problem is that this would crash Graal if
it's producing an endless loop, and people always
do scripting errors, so it's not supported.

btedji 02-25-2002 10:04 PM

Why would that crash graal, is it a overflow issue?

You should just limit the number of times it can loop, could that work?

Admins 02-25-2002 10:26 PM

Hmm actually if we add a new message code
like #M (to decode a message code) or so then it could
work, then you would only need to keep care that
there is no #M in the string. But I don't know if this
is really needed, it will be hard to support in the new
scripting engine we are planning

Admins 02-25-2002 10:32 PM

Quote:

Originally posted by Kaimetsu

But Stefan, when Graal turns scripts into bytecode, doesn't it lose the variable names and replace them with arbitrary tokens?

Yes somethign like that. It will probably still use variable
names, but with fast lookup, and the message codes
will be pre-parsed so such a recursive message code will
not work.

Saga2001 02-26-2002 12:09 AM

Re: defining script from string
 
i am not sure, but couldn't you do something like setting them over time?
setstring client.Test,#;
client.Test,#s(client.Test)#v(this.test);
client.Test,#s(client.Test)#;
client.Test,#s(client.Test)#s(client.Test2);
or is # too much of a keyword? There has to be soime way.
Quote:

2) It looks like this in the flag list:

client.Test=#v(this.test)#s(client.Test2)
thats cause it is setting the setting...there really should be some sort of escape characters with graal. Just to reduce it for simpletons. ;)

Quote:

Originally posted by Kaimetsu


I'm guessing things like:

string1=#s(string1)
message #s(string1);
      ^ thats sick man!

I suppose strings are different, since their full names are stored in the flag list, but it could never work for variables, could it?

wouldn't it be stored in an array i believe
char* stringnames[] = {"string"};
char* stringvalue[] = {"value"};
no, probably structs would work better.

Quote:

Originally posted by Kaimetsu

Personally I'd be against it one way or another. It goes against the principles of "real" programming and introduces lots of behind-the-scenes icky stuff.

yes i agree.

btedji 02-26-2002 04:54 AM

Quote:

Originally posted by Kaimetsu


I'm guessing things like:

string1=#s(string1)
message #s(string1);

It'd say "Oh, okay, so we'll go look in string1 for the correct value. Oh, alright, string1 points us to string1, so we'll go look there. Oh, alright, string1 points us to..." until it exploded. And obviously this is just a simple example. There are much more complicated possibilities, some of which wouldn't be intuitively obvious.

Personally I'd be against it one way or another. It goes against the principles of "real" programming and introduces lots of behind-the-scenes icky stuff.

But Stefan, when Graal turns scripts into bytecode, doesn't it lose the variable names and replace them with arbitrary tokens? So surely you wouldn't be able to construct a variable's name from strings and still expect it to point to the right place in memory, since the variable name doesn't mean anything anymore? I suppose strings are different, since their full names are stored in the flag list, but it could never work for variables, could it?

Add a timeout our somethin, like say if it loops for 15 seconds or 15 times without a result then cancel the command and go to the next

nyghtGT 02-26-2002 05:52 AM

Quote:

Originally posted by Kaimetsu


But Stefan, when Graal turns scripts into bytecode, doesn't it lose the variable names and replace them with arbitrary tokens? So surely you wouldn't be able to construct a variable's name from strings and still expect it to point to the right place in memory, since the variable name doesn't mean anything anymore? I suppose strings are different, since their full names are stored in the flag list, but it could never work for variables, could it?

Kai, you scare me ...

btedji 02-27-2002 09:17 PM

Quote:

Originally posted by Kaimetsu


Workarounds, workarounds, workarounds. You can script whatever you want now, why do you need this extra method?

For super easy customization of a script im making, I have a workaround on it right now, but its not the way I would like it

Saga2001 02-27-2002 10:21 PM

Quote:

Originally posted by Kaimetsu


Not to seem harsh, but it seems pointless. It'd probably be slower than the current way anyway.

it would indeed be slower...

btedji 02-28-2002 08:02 AM

bah, i doubt the way i used it, that it would be any slower, oh well


All times are GMT +2. The time now is 08:22 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.