Page 1 of 1

Timer's miliseconds defined by variable?

PostPosted: Fri Mar 22, 2013 12:11 am
by bat78
Hello population ^-^
Well.. i am little bad at scripting (thats more then obviously by my question) ..And also my English is bad, but however i have a question.
Is it possible to define timer's time by variable:

If we can include this syntax like from C++ Pawn
Code: Select all
CreateTimer("Event Actor", "Timer1", (0+Var));
CreateTimer("Event Actor", "Timer1", Var);
CreateTimer("Event Actor", "Timer1", 0+Var);

Or maybe we have to int Var; I don't know.. :s But i think you got the idea.. so is it possible to do that or similar but with the same effect :?:

photo.png

Re: Timer's miliseconds defined by variable?

PostPosted: Fri Mar 22, 2013 12:17 am
by bat78
Sorry about the typos.

Re: Timer's miliseconds defined by variable?

PostPosted: Fri Mar 22, 2013 7:48 pm
by skydereign
Yes, any place an integer literal would work, a variable would work. But, that picture you have, doesn't make much sense as it will always set the variable to 1 (because the statement on the right is true). One thing though is timers must be of length 13ms or longer.

Re: Timer's miliseconds defined by variable?

PostPosted: Fri Mar 22, 2013 8:00 pm
by bat78
I tryed with normal variable but it does not take effect.

Re: Timer's miliseconds defined by variable?

PostPosted: Fri Mar 22, 2013 9:05 pm
by skydereign
First off, in your picture, you declared the variable after the CreateTimer, which should give you an error. Second, the following will work if you have a timer called test_timer.
Code: Select all
int length = 1000;
CreateTimer("Event Actor", "test_timer", length);

If you are still having trouble, post the actual code you are using.

Re: Timer's miliseconds defined by variable?

PostPosted: Fri Mar 22, 2013 9:31 pm
by bat78
It work only with 0+length, while length is 1000.
I am wondering if that might be made with strings like length[0] = 0; length[1] = 1000; length[2] = 2000; .. And after that use the exact one for the requested amount.
I am done with this but i don't think there is a way to define a variable that will be called only for the "even values" and another one that will be called only for the "odd values" . The only way i mind is: if (length == 1 || length == 3|| length == 5) ... but that wont define all odds. :|

Re: Timer's miliseconds defined by variable?

PostPosted: Fri Mar 22, 2013 9:47 pm
by skydereign
bat78 wrote:It work only with 0+length, while length is 1000.

It also works without the +0 before length. It sounds like you think you need to cast it with the +0.
bat78 wrote: am wondering if that might be made with strings like length[0] = 0; length[1] = 1000; length[2] = 2000; .. And after that use the exact one for the requested amount.

You wouldn't be using strings for that. You would use an array of integers, but aside from that it would just work.
bat78 wrote: i don't think there is a way to define a variable that will be called only for the "even values" and another one that will be called only for the "odd values" . The only way i mind is: if (length == 1 || length == 3|| length == 5) ... but that wont define all odds. :|

A variable can only hold one value at a time, it wouldn't make sense any other way. So naturally you can't declare a value that holds all even numbers, what value would it give when used? You can however check if a number is even or not. Instead of that if statement, use this.
Code: Select all
if(length%2==1) // odd
{
    //
}

The modulus operator will return the remainder, so if you use var%2, it will return 0 when even, and 1 when odd.

Re: Timer's miliseconds defined by variable?

PostPosted: Fri Mar 22, 2013 9:50 pm
by bat78
I know one variable can hold one number (if is not string) But It can hold 1 OR 3 OR 5 OR 6 ...(all even numbers) The question is can i make it shorter then defining all even numbers i can add in script editor xD Can we make a script partition for that?
Its a matter fact so i have to tell you what i am trying to do. I just want to make with one button to appear/disappear a menu. So it can work with % ? If that won't work (i hope it will because seems short) maybe there is a different way like:

Code: Select all
int KeyVariable = key[KEY_ENTER];
char* key = GetKeyState();
if(key[KEY_ENTER]==1 && KeyVariable==1) {
keyVariable=0
//
}
if(key[KEY_Enter]==1 && KeyVariable==0) {
KeyVariable=1
//
}


About using the % method, i use this code:
Code: Select all
KeyDown > Script Editor:
length=length+1;
if(length%2==1) // odd
{
    ChangeTransparency("Event Actor", 1.000000);
}

if(length%3==0) // even
{
    ChangeTransparency("Event Actor", 0.000000);
}


But sometimes it does not have effect in game. It does appear/disappear with the button, but not all of the times.

Maybe u can correct this way?
Code: Select all
Create Actor: var=0; var2=0;
KeyDown > Script Editor
var=var+1;
var2=var2+1;
if(var=1) {
    var=2;
               }
if(var2=1) {
    var2=1;
                }
 
if (var=1) {
    ChangeTransparency("Event Actor", 1.000000);
            }
if (var2=2) {
    ChangeTransparency("Event Actor", 0.000000);
           }

Re: Timer's miliseconds defined by variable?

PostPosted: Sat Mar 23, 2013 1:13 am
by bat78
I created my script a minute ago, i will just ask you to take a look and comment:

Actor > Key Down [M] var=var+1;
Actor > Create Actor: var=2;
Actor > Draw Actor:
Code: Select all
char*key=GetKeyState();
if (key[KEY_m]==1 && var==2) {
ChangeTransparency("Actor", 1.000000);
}

if (key[KEY_m]==1 && var==3) {
ChangeTransparency("Actor", 0.000000);
}

if (var==4) {
var=2;
}


writing_ownscript.ged
(1.86 KiB) Downloaded 142 times

Re: Timer's miliseconds defined by variable?

PostPosted: Sat Mar 23, 2013 7:51 am
by skydereign
First off, you posted some code with if statements using only one equals sign. That isn't what you want, because that will set the variable to the value, and run the if statement (unless setting the variable to zero). Next thing, length%2==1 is true when length is odd, and therefore length%2==0 is true when length is even. You have in your code length%3==0 to check if it is even, which will not work.

Re: Timer's miliseconds defined by variable?

PostPosted: Sat Mar 23, 2013 10:38 am
by bat78
nomatther how happans, my code works fine :o
I wanted way to make an actor appear and disappear with one button and it seems work :o
The odd/even numbers is a way too but not that "professional". Its the system when: all even numbers make the actor to appear and all odd make to disappear, so it takes turn to appear/disappear.

Re: Timer's miliseconds defined by variable?

PostPosted: Fri Apr 05, 2013 2:11 pm
by bat78
By the way can't we use bitwise operation to determinate the odds like so:
Code: Select all
short int number=3; //short it from 3
if (number & 1) 
true=odd=1
false=even=0

Re: Timer's miliseconds defined by variable?

PostPosted: Fri Apr 05, 2013 5:48 pm
by skydereign
I don't really think that was a question... but yes, you can use bitwise and to check parity of a number.

Re: Timer's miliseconds defined by variable?

PostPosted: Fri Apr 05, 2013 7:24 pm
by bat78
its like similarity i guess, im not that good at terming.