Suppels Posted August 24, 2012 Share Posted August 24, 2012 Hey I'm new to scar and I've been searching google constantly on how to do this but can't find anything up to date. Basically I want to make it so if F8 is pressed the script terminates. Here's the part that doesn't seem to work if KeyDown(VK_F8) then Everytime I try to execute the script it says type mismatch, anyone know what the problem might be? Cheers Quote Link to comment Share on other sites More sharing options...
FHannes Posted August 24, 2012 Share Posted August 24, 2012 KeyDown presses a character key. You need GetKeyState. [scar]if GetKeyState(VK_F8) then[/scar] Quote Link to comment Share on other sites More sharing options...
Suppels Posted August 24, 2012 Author Share Posted August 24, 2012 oh ok cheers, would I need to check if it's true or anything because I've put the code in and when I press F8 nothing happens. begin RD := 0; RN := 100; //Change 1 to the number of times you wish to loop if GetKeyState(VK_F8) then begin TerminateScript; gold:= count * 105000; exp:= count2 * 21000; RD:= RD + 1 label1stuff := ('Gold Earned - ' + IntToStr(gold)) label2stuff := ('Exp Earned - ' + IntToStr(exp)) label3stuff := ('Runs Done - ' + IntToStr(RD) + '/' + IntToStr(RN)) Wait(50); Form1_1_SafeInit; end else for R := 1 to RN do begin Thieve; Wait(100) ShopKeeper; Wait(100); SellSlot28; Wait(100); CloseShop; Wait(100); MoveSlot28; Wait(1000) end; end; Quote Link to comment Share on other sites More sharing options...
FHannes Posted August 25, 2012 Share Posted August 25, 2012 [scar]if GetKeyState(VK_F8) then[/scar] Is the same thing as: [scar]if GetKeyState(VK_F8) = True then[/scar] However, you have to loop it, you're just checking it a single time and then the script stops. It doesn't wait for you to press the key or anything. Quote Link to comment Share on other sites More sharing options...
Suppels Posted August 25, 2012 Author Share Posted August 25, 2012 This might be a stupid question but does that mean I could just put a repeat function around my code or would I have to have it looping in the background, if so how would I go about doing that? also thanks again Quote Link to comment Share on other sites More sharing options...
LordJashin Posted August 25, 2012 Share Posted August 25, 2012 You can use a TTimer component. Which will repeat a task every X seconds/mins/hours w/e you set it to. Quote Link to comment Share on other sites More sharing options...
MarkD Posted August 26, 2012 Share Posted August 26, 2012 If the script has nothing else to do, you could also make something like this: [scar] x := 1; While (x = 1) do begin Wait(100); CheckThingy; end;[/scar] Checks the key 10 times a second, so you'll have to press the key for at least 100ms to be sure it gets it. It's not clean, but I try to write working code and clean it up at the end. Tried it the other way around (clean it first, then write it), doesn't work and gives a lot of frustration I don't want to topic hijack, but since I've encountered a problem related to this topic, I'd like to post it here. If I want to press the P key, I could use KeyDown(80); Wait(100); KeyUp(80);. Why oh why am I getting a type mismatch here? The VK_KEY_P has 0x50 (80 in dec). Quote Link to comment Share on other sites More sharing options...