Page 1 of 1

Variables / Procedures

Posted: Thu May 22, 2003 12:43 am
by UZZIEL
Hi

I hope someone undestand what my prob iz and what i want to do.


What Ive got:

- Script_objects moving in a given direction.
- Ive written a whole script when/how they have to move.
- Each of them has its own trigger called with different names.
- Each trigger got its own count variable parallel to the triggered object

What I want:

- duplicate 3 times that objects with same behaviour
BUT different Triggers!
- Not to type all the things and give them xdifferent names over
and over again!
- The countervariables value must not be changed!

Whats the pr0b?

- Is it possible to make procedures?
- How to give an Object Variable over to the Script->Procedure

Practically:

script_object 1: targetname:object1
script_object 2: targetname:object2
script_object 3: targetname:object3


script_object 1 called by trigger 1[setthread:obj1]
script_object 2 called by trigger 2[setthread:obj2]
...


Code: Select all


blablabla....

obj1:

    $object1 movesouth 100
    $object1 waitmove
    level.i+=1
end

obj2:

    $object2 moveeast 100
    $object2 waitmove
    level.j+=1
end

obj3:

    $object3 movewest 100
    $object3 waitmove
    level.k+=1
end
Imagine:

I want to use all that for another x times for different script_objects/triggers.
each of it must have its own countervariable.

How to use the movement of object3 by eg.[ script_object 6: targetname:object6 ] leaving level.k counting for obj3. The
script_object3 must not be moved!

Is it possible to make $object[X] so that the variable
X is chnaged to 6 if the object6 uses it? That same for level.x+=1 ?

In the end the whole thig has to turn to kind of procedure.

I hope ya undesrtand what my prob is :oops:

hmmm

Posted: Thu May 22, 2003 6:27 am
by tltrude
Well, I'm not to clear on what you are trying to do, but this should help with the variables.

In a prep thread or in prespawn, set the value of your counters to 0.

level.i = 0 // not a good idea to use "i" because a lot of scripts use it as "local.i".
level.j = 0
level.k = 0

To update the counters, use these lines.

level.i ++
level.j ++
level.k ++

That adds one to the value. You can also do it this way.

level.i = (level.i + 1)
level.j = (level.j + 1)
level.k = (level.k + 1)

Ok now, if you want to use one of the counter values you can do this.

if (level.j == 3)
{
Put what happens here
}

The action will be skipped if the counter variable (value) is not 3.

I hope that helps!

Posted: Thu May 22, 2003 10:00 am
by Parts
I'm not sure I totally understand what you are asking however you can refer to items by constructing them in code.

For example:

Code: Select all


For (local.i=1; local.i<=6; local;i++)
{
   //Have target objects name $target1, $target2, $target3,$target4,$target5,$target6
   $( "target" + local.i) moveeast 100
}

Posted: Thu May 22, 2003 11:51 am
by UZZIEL
thanx so far for that - i expected ive been not fully understood - but in parts.

tltrudes- info on local.i and level.i is very helpful in my part thx. About counting and if clauses there is no prob. c++ basic stuff is no prob for me
Since a lot is similar from mohaa scripting 2 c/c++ it helped me a lot.

part - you almost understood what my prob iz. that "afterfixes" (hope that is the opposite of prefixes) can be done by variables as i undestood from your example. You call it here by a "for loop" counting from 1 till 6.
In my case i want to teach what trigger in my map uses it.

-In your script target1 till target6 is moving to east about 100.
-In my case eg target6 wants 2 move about 100 coz only that is triggered.
All other targets do nothin.

Also that "afterfix" is an integer type in your example - but is it possible 2 use strings?

Im constructing here an example on yours:

in my map: $triggera->trig; $triggerb->trig; $triggerc ->trig; $targeta;$targetb;$targetc

Code: Select all

 
trig:

     $( "target" + [string]) moveeast 100 
     $( "target" + [string[) waitmove
     level.[string] ++

end
the string changes in reference to the $trigger that calls it. If eg. $triggerb calls it, the target changes to targetb and level.[string] to level.b.

So what I have to do, so that this thread recognizes which trigger has
called it?

Guess

Posted: Thu May 22, 2003 12:35 pm
by tltrude
This is just a guess, but are you trying to make a giant Mohaa chess game? You are going to have to tell us what it is for, if you want help.

Posted: Thu May 22, 2003 12:45 pm
by UZZIEL
hhehe, not really - but worth a try :D

Ive made a cardsystem that works as counter for hits on a target.
just like in a car (tachometer) for kilometers.
There is not only one target but 36. I dont want to write an huge script for every target - it would be too large. As you see it uses always the same procedure. So there must be a way to turn that whole thing into a procedure/method.

Posted: Thu May 22, 2003 12:48 pm
by Parts
yes you can use strings as well as numbers

ok from what you have said you could make a generic thread that looked something like as follow, hopefully this will help:

Code: Select all


// local.Trigger is the trigger you want to move
// local.Direction is either "North", "East", "South" or "West"
// local.Distance is the distance you want the trigger to move
MoveADirection local.Trigger local.Direction local.Distance:

Switch (local.Direction)
{
   case "North":
      local.Trigger movenorth local.Distance
      break
   case "East":
      local.Trigger moveeast local.Distance
      break

   case "South":
      local.Trigger movesouth local.Distance
      break

   case "West":
      local.Trigger movewest local.Distance
      break

}

end
you could then call this for you triggers wherever you wanted something like:

Code: Select all

thread MoveADirection $("MyTrigger" + "a") "West" 100
$("MyTrigger" + "a") waittill move

Posted: Thu May 22, 2003 1:30 pm
by UZZIEL
cool :D
and whats about that part with recognition - what trigger calls the thread?
How to give over an value of the mapped trigger in radiant to the thread in the script.

eg. i create
- an trigger and give setthread/recognize ; string/a
- an script_object targetname/objecta
in the radiant.

in the script:

Code: Select all


recognize:

   $("object" + string) movewest 100
   $("object" + string) waitmove

end
So coz i set forthe trigger: key->string and value->a that script has to change $("object" + string) to $("object" + "a") and then my $objecta moves.

Would this work?

Posted: Thu May 22, 2003 11:40 pm
by nuggets
ermmm... not sure exactly still what ur looking 4 after reading it twice but i'll try 2 help

1stly, give everything the same targetname, then make an array in the script

the in the scripting use self.targetname[1] etc to move them all???

explain in the most simplest terms what u want and i'll try as much as Parts and tltrude have 2 help ya, i always like a fresh challenge

Posted: Fri May 23, 2003 7:43 am
by bdbodger
The self keyword is set to the object that calls a thread . any object can hold variables such as $object1.mycounter $object1.targetname $object1.target ... etc . If several objects have the same targetname then a targetname array is created $object1[1] $object1[2] ... etc . Then you can see how many you have $object1.size returns the number of objects with that targetname . # is used for numbers .

So what to do :
Give the trigger a set value key:#set value:1
Give the trigger a thread to run key: setthread value: obj1
Give the object the same set value key:#set value:1


do that for all the objects useing the same targetname but different #set values . when the trigger is triggered you can read it's #set value .

obj1:
local.setnum= self.set
for (local.i=1:local.i<$object1.size+1:local.i++)
if $object1[local.i].set=local.setnum
{
$object1[local.i].mycounter++
( you may have to assign it to a variable first don't think so but not sure)
local.mycounter = $object1[local.i].mycounter
local.mycounter++
$object1[local.i].mycounter=local.mycounter
$object1[local.i] movesouth 100
$object1[local.i] waitmove
}
end

What happens is if the set value of the trigger ( self ) matches the set value of one of the $object's set values , then the thread is run setting the mycounter variable of the $object that matches higher by one and moves that object . So if any $trigger , $object pairs that share the same set value call this thread , this thread will move the object south 100 and set it's counter higher by 1 . You can make a thread for each direction you want to move and have the trigger call then instead

Posted: Fri May 23, 2003 10:23 am
by nuggets
if a switch is operating something else, although the switch trigger will be "self" the targetname can be recognised as a prefix or suffix for the thing it is triggering

Posted: Tue May 27, 2003 11:17 pm
by UZZIEL
thx to all

all your posts helped me fnally this night to go futher after now 9 weeks stop. Sorry for nope reply - was bad ill.

Man i love this forum. :lol: