Home   Help Search Login Register  

Author Topic: uh, variable name problem  (Read 1477 times)

0 Members and 1 Guest are viewing this topic.

Offline Garcia

  • Members
  • *
  • Leeds United is the best football team...EVER!
uh, variable name problem
« on: 30 Aug 2006, 15:05:17 »
I need a to have different names for global variables depending on the player. I got a global variable, variable_1. A random number of players may run the same script that uses this variable, and they all may give it a different string (locally), before they PV (using CoC NS to PV strings) it. From the variable is PVed and until the string in it is actually used, there must be a 1 second delay to make sure all clients have got the string.

Problem is, while player A sets the variable to a certain string, and then PVs it, at almost the same time player B does the same, though he assigns another string to the same variable. This then leads to that a script then runs using the variable set by player B, when it should have used the variable set by player A. Therefor I need some way to have a different variable for each player, but all clients must be able to use that variable, and because the amount of players may vary from 2 to 50, or even more for all I know, I just simply can't sit down naming the variables 'var1' for player 1,
'var2' for player 2 etc. :blink:

And yes, this is a problem cause by the fact that it's about multiplayer, but the problem itself is not directly linked to multiplayer, so I feel it fits more here than in the MP board.

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re: uh, variable name problem
« Reply #1 on: 30 Aug 2006, 15:33:09 »
I was about to move this to the MP board when I saw your last comment.  You have clearly thougth about it, though I am not convinced you are correct.  Let's see if this helps you (if not it is off to MP with this thread) :)

Try:
Give each unit a name
create each variable using the call and format commands.  It is a while since I have done this but it would be something like:

call format["Var_%1 = whatever",name unit1]

This should create a variable called Var_nameofunit1 and set its value to whatever

Offline Garcia

  • Members
  • *
  • Leeds United is the best football team...EVER!
Re: uh, variable name problem
« Reply #2 on: 30 Aug 2006, 16:02:02 »
hmm, seems it works, though now I have to see if I can get this to work when PVing the variable using CoC NS :D

So I'll let you know if this is what I need or not :thumbsup:

uh, this got ugly :confused:

So, new possible solution, is it possible to break a string up into letters in an array? i.e, you got _var1 = english, then you break it up to [e,n,g,l,i,s,h]...I'm quite sure the editors depot had something like that before the crash.

Meanwhile, I'll see if the CoC team got a way to make the global variable thingy work...
« Last Edit: 30 Aug 2006, 16:18:39 by Garcia »

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re: uh, variable name problem
« Reply #3 on: 30 Aug 2006, 16:52:17 »
I am not aware of any reason why 'whatever' cannot be an array of the type [e,n,g,l,i,s,h]

Offline Garcia

  • Members
  • *
  • Leeds United is the best football team...EVER!
Re: uh, variable name problem
« Reply #4 on: 30 Aug 2006, 21:04:55 »
well, I need some way to transform a word to an array of the letters, like having the word 'english' saved as a string, and then run some funky function or something to make that string an array where each element is one letter from the word, i.e [e,n,g,l,i,s,h].

And just as a note, this is where we drift into OFP scriptingland that I got no knowledge of :confused:

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re: uh, variable name problem
« Reply #5 on: 30 Aug 2006, 23:20:28 »
Not sure why you want to but here is some code that will do it for you:

Code: [Select]
_array = ["E","n","g","l","i","s","h"]

_word = ""
_i = 0
#loop
_letter = _array select _i
_word = format["%1%2",_word,_letter]
_i = _i + 1
if (_i < count _array) then {goto"loop"}
hint _word
exit

Offline Garcia

  • Members
  • *
  • Leeds United is the best football team...EVER!
Re: uh, variable name problem
« Reply #6 on: 30 Aug 2006, 23:40:55 »
I need it the other way around. I want to end up with [e,n,g,l,i,s,h] when I started with _word = english ;)

Offline Raptorsaurus

  • Editors Depot Staff
  • *****
Re: uh, variable name problem
« Reply #7 on: 31 Aug 2006, 00:37:33 »
I do not think it is possible to break a string up. OFP does not have any string manipulation functions.  You cannot, for example, do this:

Code: [Select]
_string = "english"
_newstring = "english" - "e"

This will not yeild: "nglish"

Since you can make global variables by mixing numbers with alpha characters, maybe you chould try this.

For example:

In your init.sqs put this:

Code: [Select]
possibleplayers = 0
Then in the script that makes a unique global for each player do this:

Code: [Select]
_unit = _this select 0
call format["Var_%1 = _unit", possibleplayers]
possibleplayers = possibleplayers + 1

You could also try keeping track of all the players by adding them to an array

In you init.sqs:

Code: [Select]
playerlist = []
In the script than runs for each player in the game:

Code: [Select]
_unit = _this select 0
playerlist = playerlist + [_unit]

Why do you need to have a unique variable name for each player? What do you want to do with those variables? If you explained more what your final aim was, someone might be able to come up with an alternate solution.

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re: uh, variable name problem
« Reply #8 on: 31 Aug 2006, 02:22:06 »
Yep Garcia, i agree with Raptosaurus;
It's time to tell more about what you're after with that.

I've been monitoring the thread now since it started, but i couldn't get a chance yet, how to
help you.

I must admit i could've said too that from something to string ain't possible but since there's always
a bigger fish i didn't want to make an obsolete statement like a: no way
(ya know, sometimes ppl appearing with solutions never being heared before).

Also i'd suggest to move the thread over to MP, because whatever will come out, you will need
to inform the clients (maybe even seperately one by one).

Terox for example has lots of experience with stuff like what you're after and he's almost only watching (or answering)
in MP Section.

btw - whatever you're trying to do: I don't believe that you've taken the right direction with trying to do it by them player's names
I'd rather say that you should have concentrated more on Thobson's first advice to give each unit a seperate name. I'm sure you'd
have saved one day of waiting for the correct reply by that, even if it wouldn't have solved your problem, but you would have been
one step further.  ;)

What can be the problem to name 50 units and put them in init.sqs into an array (in case they're alive) and use this array as a base?
If ya don't get what i mean continue searching for the 'perpetum mobile', but i'm sure you're more after getting a solution than doing
it only that way you first thought it's the right one.

 :blink: Sorry if you feel offended by my post in any way, that wasn't intended to be and i hope it doesn't look like this - just wanna
shake you out of the one-way situation where you are heading into atm.

:edit - only added the point in which i agree with Raptosaurus (doesn't mean that i don't agree in other points with him but especially
in this one  :D)

~S~ CD
Dont argue with idiots....they will bring you down to their level and beat you there with experience.

How to use Waypoint type Scripted

Offline Garcia

  • Members
  • *
  • Leeds United is the best football team...EVER!
Re: uh, variable name problem
« Reply #9 on: 31 Aug 2006, 09:53:01 »
1: I'm simply after sending a string to all clients, but I can't use CoC NS when doing it unless I get the different global variable name depending on player to work. And I am still trying to figure out how to use Thobsons first suggestion (as that was what I initially was after), but I took it over to CoC forums, because I think they are more likely to know how to fit this 'call format["Var_%1 = value",1]' into this '[[], format["variablename={%1}",value] ] call fNRemoteCall' :confused: (as I see it, the first one have to be in the second one, but at the same time the second one have to be in the first one... ???).

2: Yes, now this is turning into a MP thread it seems, but initally it wasn't, that's why I posted it here ;)

3: I'm not really trying to do it by players name since the players name may be "A B C D", and I don't think the variable will like that space between the letters...so if I get the global variable thingy to work, I will use a different number for each player.

4: The problem with adding a name to every player and go from there is that this is for an addon, and therefor I don't know what people will name players, I don't know if they even will name the players. Besides, going from names, it might cause some problems when people die too :confused: