Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
3 registered members (AndrewAMD, Ayumi, NewbieZorro), 14,141 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Skills and variables - help! #5347
07/07/01 09:48
07/07/01 09:48
Joined: Mar 2001
Posts: 1,825
London, England
Keith B [Ambit] Offline OP
Expert
Keith B [Ambit]  Offline OP
Expert

Joined: Mar 2001
Posts: 1,825
London, England
Hi, this might even be classed as a Beginner's Topic, if so sorry...

I have just written a long script that hands 3d fighting (no collisions as yet though...). The whole thing is designed so that the same function can be accessed by different characters.

So... I have one character and when the action that calls the function is applied to him, everything works perfectly.

Then another character - and he's going crazy, and messing up the first character.

Now obviously (I think), this is because of the difference between skills and variables... When one character is using the script it's fine because the variables only apply to him, but when two characters use it presumably the variables get messed up. I am already using a helluva lot of skills, and I thought I had used them in the right places so that the variables would remain local... I can't just play it safe and make everything a skill, as I would need way more than forty...

Er, so in a convoluted way, what I am asking is quite simple: Can someone please explain to me, as though I was three years old, exactly when it's okay to use variables instead of skills in a script that must be used by more than one character...

Thanks, sorry if this is really basic.
Cheers,
Keith


Re: Skills and variables - help! #5348
07/08/01 07:53
07/08/01 07:53

A
Anonymous
Unregistered
Anonymous
Unregistered
A



Hi Ambit,

as you alreaqdy pointed out, variables are global i.e If you change them in any action the change would effect all other entities using the same variable. The entity SKILLS are local i.e they exist per entity. 3DGS uses cooperative multitasking so if your function or action reaches a WAIT instruction, control is given back to the engines "dispatcher" and another action is given control. i.e you can only be sure that a variable has not been changed it's value before a wait instruction. As you have already noticed, the way you do use those variables, messes up the whole thing. Now if you are in need of more "local" variables (more then the 48 entity skills give you) you could cheat using an array. In the upcoming features file JCL has added a description how to use arrays as local varables. The idea comes from my array tutorial. Look at the description below which is taken from the upcoming features readme file :

quote:

Local variables and additional entity skills
You can use multidimensional arrays to add local variables to
functions - variables that are only used within a certain function
and nowhere else. Local variables can be used for unlimited entity
skills. Suppose the 48 entity skills are not enough for a certain
type of entity - you need 100 skills. Just defining an array[52]
to get a total of 100 skills won't work when you have more than
one entity of that type.

If WDL functions would support local variables, you could just define
a local array[52] within the entity action. Well, you can do this
already, through defining a 'pool' of local variables in an array
outside the function:

var ent100_skill[5200]; // enough for 100 entities, 52 skills each
var ent100_offs = 0; // index offset into the array

define _local my.skill48; // use my.skill48 to store the index offset

action ent100 // directly attached to the entity
{
_local = ent100_offs; // store the current array offset
ent100_offs += 52; // and reserve 52 array elements for this action
if (ent100_offs >= 5200) // check whether we have enough skills left
{ beep; beep; return; } // indicate an error (too much entities)
...

while (1) // entity main loop
{
...
temp = ent100_skill[_local+0]; // access first additional skill
...
temp = ent100_skill[_local+51]; // access last additional skill
...
wait(1);
}
}

Do not forget to set ent100_offs back to 0 when loading a new level!
The idea to use arrays for additional entity skills is taken from
Ronny Funk's Array Tutorial.


hope that helped ....

greetings Ronny


Re: Skills and variables - help! #5349
07/07/01 21:47
07/07/01 21:47
Joined: Mar 2001
Posts: 1,825
London, England
Keith B [Ambit] Offline OP
Expert
Keith B [Ambit]  Offline OP
Expert

Joined: Mar 2001
Posts: 1,825
London, England
Thanks Ronny, that helps a lot... I'll go through changing as many variables to skills as I can, and if that's not enough I can try this out.
Thanks again,
Keith

Re: Skills and variables - help! #5350
07/07/01 21:58
07/07/01 21:58

A
Anonymous
Unregistered
Anonymous
Unregistered
A



Hi Ambit,

you are welcome, are you on icq ? If yes and you should have questions we can chat my icq is 67987832

greetings Ronny


Re: Skills and variables - help! #5351
07/08/01 07:49
07/08/01 07:49
Joined: Mar 2001
Posts: 1,825
London, England
Keith B [Ambit] Offline OP
Expert
Keith B [Ambit]  Offline OP
Expert

Joined: Mar 2001
Posts: 1,825
London, England
Hi Ronny -

I don't have ICQ I'm afraid, thought I use microsoft messenger (keithblount@hotmail.com).

Anyway, I found that I had to change some variables to skills, and others I just had to reset within a while loop, before the wait(1), as you suggested. So thanks again, it's now working perfectly.

Cheers,
Keith


Re: Skills and variables - help! #5352
07/08/01 17:20
07/08/01 17:20

A
Anonymous
Unregistered
Anonymous
Unregistered
A



Hi Ambit,

great to hear that it works now ..... I am not on msn thought i use icq, but i give it a whirl ....

greetings Ronny



Moderated by  HeelX, Spirit 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1