charunks 0 Posted December 29, 2003 how does the publicvariable work? I' ve tried init.sqs: ; declaring public variiables ? !(local server): exit ; standard west variables WestRecource=20000;PublicVariable "WestRecource" WestPower=0;PublicVariable "WestPower" ResM1A1=0;PublicVariable "ResM1A1" ResAH64= 0;PublicVariable "ResAH64" ;westbuildingvar' s posfac=0;publicvariable "posfac" wfacbuild=0;publicvariable "wfacbuild" posbarracks=0;publicvariable "posbarracks" barrackswbuild=0;publicvariable "barrackswbuild" varPoshp=0;PublicVariable "varPoshp" whelipbuild=0;publicvariable "whelipbuild" ;east standard variables eastRecource=20000;publicvariable "eastRecource" eastPower=0;PublicVariable "eastPower" I' ve tried declaring them in a script and TONS more of thing. Every single variable is different on every computer... I totally don' t know what to do with it anymore.... can anyone please tell me how to make variables public (so if x=1 on on computer, x=1 on overy computer that plays the same game) ???????????????? Share this post Link to post Share on other sites
RED 0 Posted December 29, 2003 The init.sqs is run on all clients, there is no need to force it to run on the server. <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> ; standard west variables WestRecource=20000 WestPower=0 ResM1A1=0 ResAH64= 0 ;westbuildingvar' s posfac=0 wfacbuild=0 posbarracks=0 barrackswbuild=0 varPoshp=0 whelipbuild=0 ;east standard variables eastRecource=20000 eastPower=0 Using publicvariables causes lag so it is best to not use them when you can avoid it. RED Share this post Link to post Share on other sites
charunks 0 Posted December 29, 2003 thnx I need to share them with the clients. Am I right that this way everyone has a copy of the variables, so if there are 5 clients, there are 6 copies (5 clients, 1 server)of one variable? How do I use the public variable? Share this post Link to post Share on other sites
RED 0 Posted December 29, 2003 Yes all the clients have a copy of the variables. When using the public variable it is usualy best to have a slight pause between each one: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> barrackswbuild=0;publicvariable "barrackswbuild" ~0.5 varPoshp=0;PublicVariable "varPoshp" ~0.5 whelipbuild=0;publicvariable "whelipbuild" This should make them work more reliably. RED Share this post Link to post Share on other sites
bn880 5 Posted December 29, 2003 Take this to heart: You do not delcare PublicVariables You send variables with PublicVariable Share this post Link to post Share on other sites
charunks 0 Posted December 29, 2003 thnx.... I delayed my variables... If the command sends variables., does it mean I have to loop then like this to keep them up to date? Quote[/b] ]; sending public variiables ? !(local server): exit ; standard west variables WestRecource=20000;PublicVariable "WestRecource" ~0.5 WestPower=0;PublicVariable "WestPower" ~0.5 ResM1A1=0;PublicVariable "ResM1A1" ~0.5 ResAH64= 0;PublicVariable "ResAH64" ~0.5 ;westbuildingvar' s posfac=0;publicvariable "posfac" ~0.5 wfacbuild=0;publicvariable "wfacbuild" ~0.5 posbarracks=0;publicvariable "posbarracks" ~0.5 barrackswbuild=0;publicvariable "barrackswbuild" ~0.5 varPoshp=0;PublicVariable "varPoshp" ~0.5 whelipbuild=0;publicvariable "whelipbuild" ~0.5 ;east standard variables eastRecource=20000;publicvariable "eastRecource" ~0.5 eastPower=0;PublicVariable "eastPower" ~0.5 #update ; standard west variables PublicVariable "WestRecource" ~0.5 PublicVariable "WestPower" ~0.5 PublicVariable "ResM1A1" ~0.5 PublicVariable "ResAH64" ~0.5 ;westbuildingvar' s publicvariable "posfac" ~0.5 publicvariable "wfacbuild" ~0.5 publicvariable "posbarracks" ~0.5 publicvariable "barrackswbuild" ~0.5 PublicVariable "varPoshp" ~0.5 publicvariable "whelipbuild" ~0.5 ;east standard variables publicvariable "eastRecource" ~0.5 PublicVariable "eastPower" ~0.5 goto "update" like this? Share this post Link to post Share on other sites
RED 0 Posted December 29, 2003 No, assuming the variables have been recieved by each client, they will not be changed. <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> ; sending public variiables ? !(local server): exit ; standard west variables WestRecource=20000;PublicVariable "WestRecource" WestPower=0;PublicVariable "WestPower" ResM1A1=0;PublicVariable "ResM1A1" ResAH64= 0;PublicVariable "ResAH64" ~0.5 ;westbuildingvar' s posfac=0;publicvariable "posfac" wfacbuild=0;publicvariable "wfacbuild" posbarracks=0;publicvariable "posbarracks" ~0.5 barrackswbuild=0;publicvariable "barrackswbuild" varPoshp=0;PublicVariable "varPoshp" whelipbuild=0;publicvariable "whelipbuild" ~0.5 ;east standard variables eastRecource=20000;publicvariable "eastRecource" eastPower=0;PublicVariable "eastPower" Try that, it will only send four variables per packet from this script at the most. RED Share this post Link to post Share on other sites
bn880 5 Posted December 29, 2003 Hehhe, just to be a little evil, I would remove all the pauses there... to fit as many of the variables on one datagram/packet Share this post Link to post Share on other sites
charunks 0 Posted December 29, 2003 thnx I got it to work now... with less lagg and with up to date values, every time the variable changes, I give the publicvariable command and it works perfect!! I spend a whole day finding that out! thnx again! Share this post Link to post Share on other sites
bn880 5 Posted December 29, 2003 thnx I got it to work now... with less lagg and with up to date values, every time the variable changes, I give the publicvariable command and it works perfect!!I spend a whole day finding that out! thnx again! Yes and you are lucky, I could not find this out for over a month when OFP first came out... go figure. Share this post Link to post Share on other sites
walker 0 Posted December 29, 2003 Hi charunks bn880 often fails to blow his own trumpet so I will do it for him If you are realy getting into MP programing you may want to look at http://www.thechainofcommand.com/docs/ In the right had fram of that page is Quote[/b] ]CoC_LIBNETWORK it will give you a great deal of information and research done by the team at the CoC in particular bn880 and Dinger.bn880 is the resident network expert in OFP at The Chain of Command. He is in charge of creating CoC Network Services you can download the latest version from a link on the above page. You will also want to look at the feature synopsis on this pagehttp://www.website.thechainofcommand.net/coc_network_services.htm There is also a link on that page to the earlier release version. Kind Regards Walker Share this post Link to post Share on other sites
Taurus 20 Posted December 30, 2003 yes and what if one does want to learn these things for one self? I really like what has been done i CoC, especially the artillery thingys. (how on earth did you manage your shell to behave as the laserguided bomb??) for all I know about variables is this ;is local on the server apa1 ;is local in scripts _apa1 ;sends variable to all clients and the server I'm not sure apa1=monkey1 publicVariable "apa1" making this happen? ?!(local _unit1):exit apa1="hello world!" publicVariable "apa1" exit ;---- apa1 is now "hello world!" on all clients and the server? variables declared in triggers are visible on clients and the server, or only the server? *confused* Share this post Link to post Share on other sites
bn880 5 Posted December 30, 2003 yes and what if one does want to learn these things for one self?I really like what has been done i CoC, especially the artillery thingys. (how on earth did you manage your shell to behave as the laserguided bomb??) First of all I try to help people with learning all the time, second the Network Services are not there for you not to know how public variable works... they unify most transactions needed in larger systems/missions designed in OFP. This means: less CPU load across the board if more people started using the same network services instead of 100 custom solutions all running at once. Third, use the search feature in this forum properly, and you will learn quite a bit about scripting topics on MP. I'm being very frank here when I say, I am disappointed in how few people have opted for using the CoC NS to date for all the features it provides, and at that low CPU usage. Not to mention it's free... Later alligator Share this post Link to post Share on other sites
Taurus 20 Posted December 30, 2003 To be honest. Avon Lady has in her signature something like "Some many good add-ons, but no mission to play them with" No wonder as BIS has failed to make it easy to make working MP missions that are abit dynamic. Why in the name of the egg does OFP has three modes in which to play? 1: Singelplayer 2: MP on local host 3: MP on a dedicated server I've really tried to make fun mission, but have failed several times, and now I do not know if I want to try any further. and when will ofpec be up again? "no linking" I really appricate the Coc's efforts, but making oneself familiar with this COc mod seems very complicated and time consuming, more than trying to make missions for this game. Another reason to why I kind of dislikes using other mods straight off is that "yes I did the mission, but CoC made all other things" And I can understand your disapiontment, as you've done a great work and put alot of time in this,. edit: and another thing versions... Most people that I know of doesn't have OFPR only CwC 1.46 /taurus Share this post Link to post Share on other sites
crashdome 3 Posted January 1, 2004 If I may interject: I am using CoC_NS in SOW Mod and it cannot have made my life easier. CoC_NS isn't complicated. It is just able to BECOME very complicated if one wants it to. Now that I have used it, I use it alot. I use it when I test new ideas and when I make a quick mission to play with some add-ons. In fact, I find trying to figure out a way to make variables work in a MP game WAY more difficult than trying to figure out how to use CoC_NS. I see long threads discussing a topic on simple things because it is so hard to sync clients. Somewhere in them is bn880 plugging his Network Services!! Â Truth is, if they knew how to use it... it would cut scripts and cpu usage in half or more (most-of-the-time anyway) Turns out no one really uses it... a real sad thing. It can do alot. EDIT: I wasn't going to say this, but it was bugging me... Â If you won't use CoC because you want your missions to be all "you" then you have seriously missed out on the ideas and benefits of this forum and community. Chances are even if you made the mission with nothing but your code... you probably absorbed most of it from others suggestions/comments/code anyway. It is exactly the reason there is so much animosity between add-on makers and mod makers. If they/we would all just learn that we are all in this for the same reason we would have more quality stuff to play with..... BUT that is all just my humble opinion. I am not ashamed to use anything of anyone elses well developed code if it fits my needs and gets the job done because that is priority number one to me. Share this post Link to post Share on other sites
Taurus 20 Posted January 1, 2004 EDIT: I wasn't going to say this, but it was bugging me... Â If you won't use CoC because you want your missions to be all "you" then you have seriously missed out on the ideas and benefits of this forum and community. Chances are even if you made the mission with nothing but your code... you probably absorbed most of it from others suggestions/comments/code anyway. It is exactly the reason there is so much animosity between add-on makers and mod makers. If they/we would all just learn that we are all in this for the same reason we would have more quality stuff to play with..... BUT that is all just my humble opinion. I am not ashamed to use anything of anyone elses well developed code if it fits my needs and gets the job done because that is priority number one to me. Â That wasn't what I ment. I can not find words for it in which to explain it further. Great about the "not complicated" thing. Share this post Link to post Share on other sites
bn880 5 Posted January 1, 2004 Interesting discussion, anyway thanks for the comments CrashDome. I was thinking about just this yesterday, people probably feel very satisfied about making their own custom MP solution, showing they CAN do it. And hey, for their addon or mod it may work somewhat comparably to a unified solution like NS, however the catch is something not so obvious: put these together: RTS, BAS mods, ECP, VIT APCs, DKM mods, even UA... in a single mission. Did you know each uses their own custom tailored transfer method. Almost every method requires polling of variables and thus adds CPU usage and even uses more memory. Had all the above opted for using something like the NS for their transactions, the load would be at a constand and pretty low level, no matter how many things you plug into the NS, it polls just the same, depending on how many clients are connected. The point is: no matter how efficient your MP solution is, if there are 10 others like you in the same mission, it is at least 5 times less efficient than using NS. Don't get me wrong, I am not putting down the mods etc. and just saying this because I had worked on the NS, it is about unifying and reducing _time wasted_ reinventing the wheel. Comparable to each car manufacturer inventing their own screw sizes... heh Happy New Year and stuff! Share this post Link to post Share on other sites
Taurus 20 Posted January 1, 2004 Happy new year to you all. I feel it's necessary to "reinvent" the wheel. Why, you don't learn. Take for an example JAVA For an "hobby" coder as myself, allmost everything is allready made, but still I sitt here and trym because I want to learn JAVA. The same goes for coding MP stuff in OFP. CrashDome I din't mean to upset you, and I didn't mean that I feel ashamed by using other mods, but I want to learn thats all. I sweden we have an proverb: Själv är bäste dräng. Share this post Link to post Share on other sites
bn880 5 Posted January 1, 2004 Right, you are missing an important point though, learning to learn and learning then releasing as part of major mods/addons are two different things. I already explained this, inefficiency. If you ever try to design large MP missions you will remember what I told you. Thus, you should notice my discussion is not aimed at soemone learning the basics, but someone building things for relaese at a much higher scripting level. (usually) And Java is a major inefficiency, please don't compare Java to the CoC NS. EDIT: To clear it up even more, I am talking about "ONCE YOU KNOW HOW", what do you build with and release. You have to get off this concept that someone is trying to prevent you from learning! No one is, and CrashDome is not upset at you... Share this post Link to post Share on other sites
dinger 1 Posted January 2, 2004 Sure, find your own route Taurus. A lot of Bn880's consternation concerning CoC_NS is probably due to the fact that there just aren't enough people out there who really know how to make MP scripting work, who can then appreciate what he's done. MP scripting is a black art. Testing is a bitch, and esoteric bugs can bite you when you least expect it. What CoC_NS effectively does is give us a few functions that allow us to do the things we've always wanted to do in MP: maintain arrays across a network, execute functions on specified clients or on all clients, and get updated information on the players connected and their game states. That's topside. Underneath, it takes advantage of Bn880's research into how PublicVariable works across a network,a nd how OFP handles variables to do what it does with minimal impact on gameplay. Had CoC_NS been around when I wrote the core for UA, I would have made UA go straight through NS: it's a far more elegant solution. But yeah, at the time, I was caught up in writing tons of self-modifying code, and the result is something that works, but is not nearly as elegant (but it don't eat much CPU time when it's idling :P ). But CoC_NS doesn't get supplant good ol' Publicvariable. And you still need an idea of how OFP MP works to be able to appreciate it. So yeah, find your own route. Of course, neither NS nor UA will work in 1.46. Come to think of it, most things won't work in 1.46. Share this post Link to post Share on other sites
-)rStrangelove 0 Posted January 19, 2004 /me hurries off to CoC forums  Right, that's it. This 'custom MP script testing' is starting to annoy me. I'll see if i can use CoC in 1 - 2 weeks and then come back here to report.    ( i hope this is a good idea & there's a CoC n00b guide somewhere...) Share this post Link to post Share on other sites
Taurus 20 Posted January 19, 2004 Quote[/b] ]Sure, find your own route Taurus. Yes and no, how hard can it be? I'm only trying to solve basic stuff. As some others asking about setPos things, except that mine are a little bit more "complicated" Will you turn them down as well? Quote[/b] ]Testing is a bitch You can say that again. Quote[/b] ]The other things you said about bn880's work Yes and I've said it once, and feel it necessary to say it again. I will try it later but first I will try to make something work. I'm glad when vehicles respawns correctly in MP for example. No need to bitchslap me for this. Quote[/b] ]Of course, neither NS nor UA will work in 1.46. Come to think of it, most things won't work in 1.46. No and I want it to work for 1.46 as the people that I play with isn't 1% as dedicated to OFP as most of the ppl around here. Share this post Link to post Share on other sites
SSG Plazmoid 0 Posted January 27, 2004 Something I didn't see mentioned here (but that was mentioned in a previous public variable thread) is in reference to arrays. You can't transmit an array by making it public. OFP doesn't complain it just doesn't work. Until I read that in this forum I was banging my head trying to understand why my solution worked testing on my own but in a dedicated server environment the remote clients didn't get the array. So, as far as I know this won't work: bob = [element1, element2, ...] PublicVariable "bob" Just FYI for the day you might need it Share this post Link to post Share on other sites
Softegg 0 Posted January 28, 2004 back to the basic question: a public variable should be declared/initalised in the init.sqs on each computer: BodyCount=0 GeneralKilled=false variables which can be made public: number boolean variables which not can be made public: string array another thing to say is: making values public with publicvariable "varname" is not guaranteed to reach to each client. if there is a moment with bandwith-problems or heavy stress, the client can fail to receive the new value. Share this post Link to post Share on other sites
Chris Death 0 Posted January 28, 2004 Quote[/b] ]another thing to say is:making values public with publicvariable "varname" is not guaranteed to reach to each client. And that's again a point for CoC NS, as i remember that you can also check wether the packet came thru or not. Correct me if i remember wrong BN880 ~S~ CD Share this post Link to post Share on other sites