Timer's miliseconds defined by variable?

Talk about making games.

Timer's miliseconds defined by variable?

Postby bat78 » Fri Mar 22, 2013 12:11 am

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
The future of "Game-Editor" here
User avatar
bat78
 
Posts: 816
Joined: Sun Dec 14, 2008 9:13 pm
Location: Bulgaria, Sofia
Score: 88 Give a positive score

Re: Timer's miliseconds defined by variable?

Postby bat78 » Fri Mar 22, 2013 12:17 am

Sorry about the typos.
The future of "Game-Editor" here
User avatar
bat78
 
Posts: 816
Joined: Sun Dec 14, 2008 9:13 pm
Location: Bulgaria, Sofia
Score: 88 Give a positive score

Re: Timer's miliseconds defined by variable?

Postby skydereign » Fri Mar 22, 2013 7:48 pm

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Timer's miliseconds defined by variable?

Postby bat78 » Fri Mar 22, 2013 8:00 pm

I tryed with normal variable but it does not take effect.
The future of "Game-Editor" here
User avatar
bat78
 
Posts: 816
Joined: Sun Dec 14, 2008 9:13 pm
Location: Bulgaria, Sofia
Score: 88 Give a positive score

Re: Timer's miliseconds defined by variable?

Postby skydereign » Fri Mar 22, 2013 9:05 pm

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Timer's miliseconds defined by variable?

Postby bat78 » Fri Mar 22, 2013 9:31 pm

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. :|
The future of "Game-Editor" here
User avatar
bat78
 
Posts: 816
Joined: Sun Dec 14, 2008 9:13 pm
Location: Bulgaria, Sofia
Score: 88 Give a positive score

Re: Timer's miliseconds defined by variable?

Postby skydereign » Fri Mar 22, 2013 9:47 pm

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Timer's miliseconds defined by variable?

Postby bat78 » Fri Mar 22, 2013 9:50 pm

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);
           }
The future of "Game-Editor" here
User avatar
bat78
 
Posts: 816
Joined: Sun Dec 14, 2008 9:13 pm
Location: Bulgaria, Sofia
Score: 88 Give a positive score

Re: Timer's miliseconds defined by variable?

Postby bat78 » Sat Mar 23, 2013 1:13 am

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 143 times
Last edited by bat78 on Sat Mar 23, 2013 2:13 pm, edited 1 time in total.
The future of "Game-Editor" here
User avatar
bat78
 
Posts: 816
Joined: Sun Dec 14, 2008 9:13 pm
Location: Bulgaria, Sofia
Score: 88 Give a positive score

Re: Timer's miliseconds defined by variable?

Postby skydereign » Sat Mar 23, 2013 7:51 am

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Timer's miliseconds defined by variable?

Postby bat78 » Sat Mar 23, 2013 10:38 am

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.
The future of "Game-Editor" here
User avatar
bat78
 
Posts: 816
Joined: Sun Dec 14, 2008 9:13 pm
Location: Bulgaria, Sofia
Score: 88 Give a positive score

Re: Timer's miliseconds defined by variable?

Postby bat78 » Fri Apr 05, 2013 2:11 pm

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
The future of "Game-Editor" here
User avatar
bat78
 
Posts: 816
Joined: Sun Dec 14, 2008 9:13 pm
Location: Bulgaria, Sofia
Score: 88 Give a positive score

Re: Timer's miliseconds defined by variable?

Postby skydereign » Fri Apr 05, 2013 5:48 pm

I don't really think that was a question... but yes, you can use bitwise and to check parity of a number.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Timer's miliseconds defined by variable?

Postby bat78 » Fri Apr 05, 2013 7:24 pm

its like similarity i guess, im not that good at terming.
The future of "Game-Editor" here
User avatar
bat78
 
Posts: 816
Joined: Sun Dec 14, 2008 9:13 pm
Location: Bulgaria, Sofia
Score: 88 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest