Trigger Help!

Discussions about Coding and Scripting
User avatar
Chamberly
Godlike
Posts: 1963
Joined: Sat Sep 17, 2011 4:32 pm
Personal rank: Dame. Vandora
Location: TN, USA
Contact:

Re: Trigger Help!

Post by Chamberly »

'Zac wrote:I sort of understand what Higor's saying about strings. What I think a computer needs to do to convert %P into a player name is by making a making %P a variable player name, but replace it with the actual player name?
Kinda like this:
%P entered the game.
Paper entered the game.

%P left the game.
Paper left the game.

%P hit a spiky ball and blow up!
Paper hit a spiky ball and blow up!

:loool:
Image
Image
Image Edit: Why does my sig not work anymore?
JackGriffin
Godlike
Posts: 3774
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: Trigger Help!

Post by JackGriffin »

Hellkeeper wrote:OldUnreal has a wiki which could handle all that. I'm sure Smirftsch would be glad to host all that.
I'll chat with him about it but they are much more geared towards exploring Unreal and the 227 patch differences. There's a lot going on there and including UT into the mix isn't a great idea as it could get muddy fast. This really needs it's own separate entity to grow properly.
So long, and thanks for all the fish
User avatar
Hellkeeper
Inhuman
Posts: 905
Joined: Tue Feb 25, 2014 12:32 pm
Personal rank: Soulless Automaton
Location: France
Contact:

Re: Trigger Help!

Post by Hellkeeper »

Good point, but I'm quite sure Smirftsch wouldn't mind. The wiki was created to be a general knowledge base, and the fact there are little to no info on UT (and the UT forums of OU are mostly empty) is something we're all a bit sad about, so some dynamism on this point would surely be a good thing.
You must construct additional pylons.
User avatar
Chamberly
Godlike
Posts: 1963
Joined: Sat Sep 17, 2011 4:32 pm
Personal rank: Dame. Vandora
Location: TN, USA
Contact:

Re: Trigger Help!

Post by Chamberly »

This isn't about Unreal Wiki?
Image
Image
Image Edit: Why does my sig not work anymore?
Higor
Godlike
Posts: 1866
Joined: Sun Mar 04, 2012 6:47 pm

Re: Trigger Help!

Post by Higor »

You kinda got the point, now how do you replace text using the functions I showed you?
TIP:

Define two extra string variables
- local string Processed;
- local string NonProcessed;

Initially, NonProcessed = Message;
As you process the string, you remove parts of NonProcessed, and put them in Processed using the functions.
Then you broadcast the Processed string.
This method allows you to replace multiple strings without crashing the game in case of bug.

If you work with only one variable string, you'll be checking it over and over, even the processed parts...
Problem arises if the player has the "%p" characters in his name lol, you'll end up with an infinite loop crashing the game.

So putting the processed text in Processed, while processing the NonProcessed prevents that bug/exploit.


A machine would have to
- NonProcessed = Message
- Find the wildcard in NonProcessed.
- Cut the text before wildcard and add it to Processed (to the end of it)
- Cut the wildcard now in NonProcessed as well (should be at position 0 now), but add player name in Processed (end again).
- Rinse and repeat until wildcard character isn't found, in that case, append the remaining NonProcessed string at the end of Processed.

Turn that into UScript code in a separate function named:

Code: Select all

function string ReplaceString( string Message, string Wildcard, string ReplaceWith)
{
    local string Processed, NonProcessed;
    local string aStr; //If you need an extra string to work with while doing text mangling
    ... bla bla
    return Processed;
}
If it works, save it in a text file so you can use it in your future projects.
With this, you just made a utilitary function and saved yourself time for the future.
User avatar
papercoffee
Godlike
Posts: 10453
Joined: Wed Jul 15, 2009 11:36 am
Personal rank: coffee addicted !!!
Location: Cologne, the city with the big cathedral.
Contact:

Re: Trigger Help!

Post by papercoffee »

Ferali was lurking :P
I have the permission to post his mail here :mrgreen:
Today I lurked on the forum to check how things were going, and I just stumbled this topic:
http://www.ut99.org/viewtopic.php?f=15& ... 675#p66659

which turned out into a string manipulation discussion, and due to my coding passion (string manipulation, specially at the level of the byte itself, is one of favorite topics in coding, to the point I was making parsers in UScript to interpret SQL and other fun stuff) I couldn't resist but to email you so you can let them know that NW3 has a couple of very useful string functions they can look at and use, even if just to know how they work.

More specifically, they're documented in the NW3_SDK.pdf file (in page 17), and they can check the source code for the NWUtils class along with the documentation describing it. These are pretty basic standalone functions in this single class, so they can pretty much copy and paste the functions in any other mod to use them (one or another may call another helper function, but always within the same class alone).

Examples of functions (starting with the one they're talking about):
ReplaceStr(coerce string Replace, coerce string With, coerce string Text, optional int maxReplaces)

processStrSplit(string splitStr, string srcStr, out string outStr1, out string outStr2) - splits a string in 2
StrMatch(string sA, string sB, optional bool bCaseSensitive) - compares 2 strings (and supports ? and * wildcards to match any exactly 1 character and any characters respectively)

And then for those cases where people want to store indexed settings in the shape of a string (key=value type of deal, such as "a=1;b=stuff;..."), like a database of sorts, there are these:
getValueFromSettingsString(coerce string varString, string strSettings)
hasValueFromStringList(string dataStr, int index, optional out string indexData)
hasPropertyFromStringList(string dataStr, int index, optional out string indexProperty, optional out string indexData)


And I have another source that goes a bit further beyond, which has functions and classes exclusively for string manipulation for calculating all sorts of hashes from strings (MD5, SHA-1 up to SHA-512), a JSON parser and writer (to communicate with REST web APIs which generally communicate in JSON, and which I tested with very large JSON responses to stress test it), and a few other things, which is the last item in the list I made here:
http://www.ut99.org/viewtopic.php?f=12&t=5638
(it's the UWeb source)

I planned to make also a regex function, but by then I had moved on from these little string projects of mine in UScript.

Right now I only work with PHP and Javascript exclusively (along with SQL and a few other technologies), and there string manipulations are a piece of cake to make, but it's still very interesting to create these sorts of functions in a very limited environment such as UEngine1/UT1, as it does help young programmers to develop better algorithms for other languages once they are able to creatively come up with solutions in more limited systems.
JackGriffin
Godlike
Posts: 3774
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: Trigger Help!

Post by JackGriffin »

Hellkeeper wrote:Good point, but I'm quite sure Smirftsch wouldn't mind. The wiki was created to be a general knowledge base, and the fact there are little to no info on UT (and the UT forums of OU are mostly empty) is something we're all a bit sad about, so some dynamism on this point would surely be a good thing.
I need to email him anyway so I'll bring this up and see what he thinks. With the renewed interest in UT2014 there could be a few articles penned by returning devs if we get lucky.
So long, and thanks for all the fish
User avatar
'Zac
Experienced
Posts: 111
Joined: Tue Jul 29, 2014 9:35 pm
Personal rank: Who knows.
Location: NC

Re: Trigger Help!

Post by 'Zac »

Higor wrote:You kinda got the point, now how do you replace text using the functions I showed you?
You create 2 strings and you combine them with $ to create one single string on the return. I think
this is what i think ( probably not in good form, but hopefully you know what i mean );

Code: Select all

function strings()
	local string A
	local string B
	
	{
	
	A = " before "
	B = " after "
	c = a $ b 
	return;
	
	}
Prophunt for UT99!!!
Image
Github
Higor
Godlike
Posts: 1866
Joined: Sun Mar 04, 2012 6:47 pm

Re: Trigger Help!

Post by Higor »

You're not thinking with arrays, or like a coder.
This is what the engine should do for you, now try and put it together using the functions in the previous posts.
ReplaceWith.PNG

For reference:
You're gonna have to either loop using WHILE iterator, or GOTO jumps.
WHILE makes the code readable, but limits your options (unless you're really good at making iterators).

Simply, WHILE is an IF statement that resets the code position back at the condition once the sub-code finished executing, until it returns FALSE.

Code: Select all

if ( something )
{
    DoOther();
}
Changing IF for WHILE does this:

Code: Select all

if ( something )
{
    DoOther();
    Go back to conditional.
}
If the conditional returns FALSE, then the code moves on.

Keywords you can use during WHILE:
continue; - Go back to conditional.
break; - Go below condition block (end iterator).
return (value?); - Exit function, breaks iterator obviously.

One common mistake when coding with WHILE:

Code: Select all

while ( i < 5)
{
    if ( Actors[i] == none )
         continue;
    else
         Actors[i].Destroy();
    i++;
}
Continue here prevents i++ from executing, causing an infinite loop.
For iterators don't suffer from this.
User avatar
TheDane
Masterful
Posts: 660
Joined: Tue Feb 12, 2008 2:47 pm
Personal rank: Happy fool :-)

Re: Trigger Help!

Post by TheDane »

JackGriffin wrote:We really should take the time to build a proper searchable wiki. This sort of information presented like this belongs front-and-center someplace that everyone could use. Dane, maybe you could host it? You've got the technical knowledge to set it up properly and you would host sharing it so everyone could download the thing. I'd be happy to spend a lot of time writing response pages in the wiki then referencing them in threads here. I'd wager a lot of others would do the same. Lots of knowledge just sits idle instead of being shared, I mean just look at Higor's post. He just took String to school....So well done. +Karma for Higor.
As I already mentioned at my forums I will be happy to suply webspace and setting a wiki up if anyone or multiple persons can provide the time to update it.

Now since my name got mentioned in this I'll give my two cents hehe. I think that a wiki should not be a mix of different Uengines, because it's so easy to get fooled into thinking that something is working in your mod and then after multiple tests have failed you go back and study the wiki Again - only to find that the article you followed may be attached to another engine. So ... I would be happy to host a wiki, but I think it should be for UT99 engine only. Modding for UT99 is tricky eneough as it is, no need to add to the confuzion by mixing engines in the same wiki.
Retired.
Post Reply