Disclaimer: Yes I have read another StackOverflow posts similar to mine, but none were using RegEx on the title, and I couldnt find a solution.
I need to open a certain window that is like this:
PlayerName - Game Version 1.2.15
where PlayerName can be everything (like aywradwe, john or flyingcar82)
I can get the player name from a certain function getName() that is irrelevant for my question and its working properly.
playerName = getName()
And then I tried to open the correct window by using that playerName variable and RegEx to match any possible version of the game.
SetTitleMatchMode RegEx
playerName = getName()
IfWinExist, playerName - Game Version.*
{
WinActivate
Sleep, 500
WinMaximize
}
But it tries to match the title using "playerName" and not its value. I also tried with %playerName% and it doesnt work either...
What am I missing?
Two problems here, and they come from using the legacy syntax wrong.
Problem 1:
playerName = getName()
You're using the deprecated legacy way of assigning literal text to a variable (=).
Now the variable playerName holds the literal text "getName()".
:= should be used to assign the result of an expression to a variable:
playerName := getName()
Problem 2:
Usage of the deprecated legacy IfWinActive command.
Not exactly a problem on it's own, but combined with wrong usage of the legacy syntax it is. In a legacy statement there you'd indeed refer to the variable by doing %playerName%, and that would work if you fixed Problem 1.
But lets do it the proper way and use the newer WinExist() function:
if (WinExist(playerName " - Game Version.*")) ;concatenate the contents of a variable and string
{
WinActivate
Sleep, 500
WinMaximize
}
Overall, I'd recommend trying to get rid of the legacy syntax.
Here's a good page on the documentation to get you started between the differences:
https://www.autohotkey.com/docs/Language.htm
Related
local playerName = OykkoIsBack
Players.(playerName).Character.Humanoid.JumpPower = 100
so I want to set my jump power to the variable that has the players name? im new to roblox
scripting and this happened in my output
Expected identifier, got '('
something similar to this happened
i wrote this if game.Workspace.IntValue.Value = 0 then
print("Value is 0")
but i figured this out by adding a another = but this time i can't figure it out so i need someone to help me!
really appreciate it if you could help me!
OykkoIsBack should have double quotes around it, so the first line should be local playerName = "OykkoIsBack". Without the quotes, it is not a string and cannot be assigned to playerName.
The other issue is with Players.(playerName). The syntax for indexing a table in Lua is table[key]. In your case it should be Players[playerName]
Here is the code
local playerName = "OykkoIsBack"
Players[playerName].Character.Humanoid.JumpPower = 100
What this does is sets playerName to OykkoIsBack, then it gets the humanoid of the player with playerName and sets their jump power to 100.
I’m quite new at scripting too, so I might be wrong but here’s what I think the mistake is:
First of all you put
Players.(playername).Character.Humanoid etc.
I think ‘playername’ shouldn’t have brackets?
Secondly, you just set the jumpPower to 100?? Try replacing the 100 with a variable, so after the = try writing the variable name.
I think this because the error is saying there was a bracket where it expected something else (from what I know) so I think it’s just the playername brackets.
I have two arrays of strings and I want to check if a string of array a matches a string from array b. Those strings are phone numbers that might come in different formats. For example:
Array a might have a phone number with prefix like so +44123123123 or 0044123123123
Array b have a standard format without prefixes like so 123123123
So I'm looking for a regex that can match a part of a string like +44123123123 with 123123123
Btw I'm using Swift but I don't think there's a native way to do it (at least a more straightforward solution)
EDIT
I decided to reactivate the question after experimenting with the library #Larme mentioned because of inconsistent results.
I'd prefer a simper solution as I've stated earlier.
SOLUTION
Thanks guys for the responses. I saw many comments saying that Regex is not the right solution for this problem. And this is partly true. It could be true (or false) depending on my current setup/architecture ( which thinking about it now I realise that I should've explained better).
So I ended up using the native solution (hasSuffix/contains) but to do that I had to do some refactoring on the way the entire flow was structured. In the end I think it was the least complicated solution and more performant of the two. I'll give the bounty to #Alexey Inkin for being the first to mention the native solution and the right answer to #Ωmega for providing a more complete solution.
I believe regex is not the right approach for this task.
Instead, you should do something like this:
var c : [String] = b.filter ({ (short : String) -> Bool in
var result = false
for full in a {
result = result || full.hasSuffix(short)
}
return result
})
Check this demo.
...or similar solution like this:
var c : [String] = b.filter ({ (short : String) -> Bool in
for full in a {
if full.hasSuffix(short) { return true }
}
return false
})
Check this demo.
As you do not mention requirements to prefixes, the simplest solution is to check if string in a ends with a string in b. For this, take a look at https://developer.apple.com/documentation/swift/string/1541149-hassuffix
Then, if you have to check if the prefix belongs to a country, you may replace ^00 with + and then run a whitelist check against known prefixes. And the prefix itself can be obtained as a substring by cutting b's length of characters. Not really a regex's job.
I agree with Alexey Inkin that this can also nicely be solved without regex. If you really want a regex, you can try something like the following:
(?:(\+|00)(93|355|213|1684|376))?(\d+)
^^^^^^^^^^^^^^^^^^^^^ Add here all your expected country prefixes (see below)
^^^ ^^ Match a country prefix if it exists but don't give it a group number
^^^^^^^ Match the "prefix-prefix" (+ or 00)
^^^^ Match the local phone number
Unfortunatly with this regex, you have to provide all the expected country prefixes. But you can surely get this list online, e.g. here: https://www.countrycode.org
With this regex above you will get the local phone number in matching group 3 (and the "prefix-prefix" in group 1 and the country code in group 2).
I have two Visualforce pages, and for several reasons I've decided it is best to pass a datetime value between them as a string. However, after my implementation my date always appear to be null even though my code seems to compile.
I have researched quite a few formatting topics but unfortunately each variation of the format() on date time seems to not produce different results.
The controller on page 1 declares two public variables
public datetime qcdate;
public String fdt;
qcdate is generated from a SOQL query.
wo = [SELECT id, WorkOrderNumber, Quality_Control_Timestamp__c FROM WorkOrder WHERE id=:woid];
qcdate = wo.Quality_Control_Timestamp__c;
fdt is then generated from a method
fdt = getMyFormattedDate(qcdate);
which looks like this
public String getMyFormattedDate(datetime dt){
return dt.format(); }
fdt is then passed in the URL to my next VF page.
String url = '/apex/workordermaintenanceinvoice?tenlan='+tenlan +'&woid=' + woid + '&invnum=' + invnum + '&addr1=' + addr1 + 'fdt=' + fdt;
PageReference pr = new PageReference(url);
I expected when calling {!fdt} on my next page to get a proper string. But I do not.
UPDATE:
Sorry I guess I should not have assumed that it was taken for granted that the passed variable was called correctly. Once the variable is passed the following happens:
The new page controller creates the variable:
public String fdt
The variable is captured with a getparameters().
fdt = apexpages.currentPage().getparameters().get('fdt');
The getfdt() method is created
public String getfdt(){
return fdt;
}
Which is then called on the VF page
{!fdt}
This all of course still yields a 'blank' date which is the mystery I'm still trying to solve.
You passed it via URL, cool. But... so what? Page params don't get magically parsed into class variables on the target page. Like if you have a record-specific page and you know in the url there's /apex/SomePage?id=001.... - that doesn't automatically mean your VF page will have anything in {!id} or that your apex controller (if there's any) will have id class variable. The only "magic" thing you get in apex is the standard controller and hopefully it'll have something in sc.getId() but that's it.
In fact it'd be very stupid and dangerous. Imagine code like Integer integer = 5, that'd be fun to debug, in next line you type "integer" and what would that be, the type or variable? Having a variable named "id" would be bad idea too.
If you want to access the fdt URL param in target page in pure Visualforce, something like {!$CurrentPage.parameters.fdt} should work OK. If you need it in Apex - you'll have to parse it out of the URL. Similar thing, ApexPages.currentPage() and then call getParameters() on it.
(Similarly it's cleaner to set parameters that way too, not hand-crafting the URL and "&" signs manually. If you do it manual you theoretically should escape special characters... Let apex do it for you.
I'm writing a smart contract where the user send a hashed string : the answer of an asked question (because I don"t want it to be public in the blockchain).
It is compared to the correct hashed answer:
function answerQuestion(bytes32 _answer) notAnswered returns (string){
if(_answer == keccak256(answer)){
isAnswered = true;
winner = msg.sender;
return pos;
}
return "WRONG";
}
To check if it works I hash the correct answer in an online tool (https://emn178.github.io/online-tools/keccak_256.html)
It gives me something like 57315cf71be5ffcaf957b9cc196b322e1c4d5a1832396abcee71d05d8caf41a6
and I parse it as the parameter in the browser solidity. But it returns:
Error encoding arguments: SyntaxError: Unexpected token c in JSON at position 6
Any idea how should I fix this?
I am developing a smart contract using the Remix IDE and I ran into the same issue. I solved this issue by appending 0x to the beginning of the hash.
0x57315cf71be5ffcaf957b9cc196b322e1c4d5a1832396abcee71d05d8caf41a6
I'm using Opa for a school project in which there has to be some synchronization of a textfield between several users. The easy way to solve this, is to transmit the complete field whenever there is a change performed by one of the users. The better way is of course to only transmit the changes.
My idea was to use the caret position in the textfield. As a user types, one can get the last typed character based on the caret position (simply the character before the caret). A DOM element has an easy-to-use field for this called selectionStart. I have this small Javascript for this:
document.getElementById('content').selectionStart
which correctly returns 5 if the caret stands at the fifth character in the field. In Opa, I cannot use selectionStart on either a DOM or a dom_element so I thought I'd write a small plugin. The result is this:
##extern-type dom_element
##register jsGetCaretPosition: dom_element -> int
##args(node)
{
return node.selectionStart;
}
This compiles with the opp-builder without any problem and when I put this small line of code in my Opa script:
#pos = %%caret.jsGetCaretPosition%%(Dom.of_selection(Dom.select_id("content")));
that also compiles without problems. However, when I run the script, it always returns "undefined" and I have no idea what I'm doing wrong. I've looked in the API and Dom.of_selection(Dom.select_id("content")) looked like the correct way to get the corresponding dom_element typed data to give to the plugin. The fact that the plugin returns "undefined" seems to suggest that the selected element does not know the member "selectionStart" eventhough my testcode in Javascript suggest otherwise. Anyone can help?
In Opa dom_element are the results of jQuery selection (i.e. an array of dom nodes). So if I well understood your program you should write something like node[0].selectionStart instead of node.selectionStart.
Moreover you should take care of empty selection and selection which doesn't contains textarea node (without selectionStart property). Perhaps the right code is tmp == undefined ? -1 : tmp = node[0].selectionStart == undefined ? -1 : tmp