proc/PHY_Training() |
ID:161533
Apr 26 2008, 6:25 am
|
|
So far I have this code that makes icons A,S,D, and F pop up on screen. I also have macros to press if for example you have to press A,S, or etc. But I want to make something to check when and if a the right key is pressed for the right icon in the PHY_Training proc. Thank you.
| |
Ok, I'll fix the code and think of a way to apply what you suggested. Thank you!
| |
Yup, you should first fix your code. Since you're interested, I'll go into more detail.
--You should mostly never use 'usr' in procs. Pass an argument or use src, when applicable. In this case, src isn't applicable since it isn't an object proc. However, it should be; so change your proc to something like a mob/player/proc instead of global /proc, and use 'src' in it to refer the the mob being handled. Also, when calling the proc, you'd now call it on the object - "object.Proc()", so do that in the verb. -I'm going to go through somewhat redundant explanations here, but the aim is to teach you so you don't repeat mistakes/bad habits in other code too, so it's okay. In any programming language, if you have something like this:
It's a bad thing and can be improved either by changing the general design or improving the efficiency of the code itself. First of all, if you are checking any value, and it didn't pass the test, and you are checking it again for another different value, you should use the ever-useful 'else' statement. Since if X equals 1, there is no reason to test if it equals 2, since it is impossible anyway (in this case, you use else-if, actually). However, any good language has something like a switch() or case proc. This allows you to cut down a long if-else-if chain down, and is more efficient as well. DM actually has a more-useful-than-average switch(). It is more flexible and has the functionality of not comparing the value again if it was already found equal to something (like if you've used elseif()). Whenever you're comparing the same value for 3 or more values (if you've got 2 values, you can usually manage with a simple if+else instead) you should use switch(). Look it up in the DM Reference to see this format (press F1 in Dream Maker). -In actuality, you can skip checking the random value at all by using a built-in proc called pick() instead of rand(). It will automatically return (randomly) one of the arguments used in it; if you utilize this, this portion of your code wouldn't need any if()s, I think. Look it up as well. | ||
For your question. You'll have to make a built-in game macro for each of the keys (technically, you don't have to, since the players can make their own) through the interface editor.
The macros should all refer to the same (hidden) verb with the key as an argument. From the verb you can then check if the key is correct or do whatever with it.
Just make sure though, that if a player sends the wrong command (or presses the wrong key;same thing) then you explicitly make him fail the test; if your only condition is sending the right command, then a pesky player might be able to cheat by making a macro to send all the possible commands "at once".