|
|
concatenating strings and arrays
#172627
12/13/07 05:51
12/13/07 05:51
|
Joined: Jun 2007
Posts: 28
Doriel
OP
Newbie
|
OP
Newbie
Joined: Jun 2007
Posts: 28
|
Hello,
I have a small problem that I hope someone has seen before. In my game, I am trying to track a user's actions towards a patient along with the game time of each action. The user can view his/her last 15 actions at any time for any given patient.
Now, since there are multiple patients, I decided to use a multi-dimensional (faked) array to store the actions. I have a nice little panel that shows up and displays the list of actions. Everything works fine, except the game time.
For the game time, I have a string variable game_time that is updated every iteration. So when it's time to track a message, I simply do something like the following:
p_actions_taken[currentPatient * p_num_of_actions[currentPatient]] = "my action message here"; p_num_of_actions[currentPatient] = p_num_of_actions[currentPatient] + 1; p_time_of_action[currentPatient * p_num_of_actions[currentPatient]] = game_time;
When I try concatenating the game_time into it, it always shows the current game_time, not the time when the array was updated.
I am assuming the array only holds a pointer to the game_time string instead of a copy of the actual string. Is there any way around this? I was hoping there was a way to concatenate strings without using str_cat. I believe if I was able to do something as follows, it would work:
p_actions_taken[currentPatient * p_num_of_actions[currentPatient]] = game_time + " " + "my action message here";
But that only gives an error.
Any ideas?
Regards,
Doriel
|
|
|
Re: concatenating strings and arrays
[Re: Doriel]
#172629
12/15/07 08:05
12/15/07 08:05
|
Joined: Jul 2006
Posts: 503 Australia
adoado

User
|

User
Joined: Jul 2006
Posts: 503
Australia
|
Quote:
I am assuming the array only holds a pointer to the game_time string instead of a copy of the actual string
Arrays I think only hold numbers (vars) and not strings directly, so it would be a pointer to a string that it would be holding.
Maybe try
p_time_of_action[currentPatient * p_num_of_actions[currentPatient]] = str_create(game_time);
I am not fully understanding the problem (thats my fault - I am a little sleepy ) - so I am not sure whether this is the right answer or not 
Somehow copy the contents of "game_time" into a new string and then use the new string so the array value is no longer pointing to game_time...
Thanks, Adoado
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|