Amend an append

Started by Slasher, Fri 20/06/2014 07:26:10

Previous topic - Next topic

Slasher

Hi,

Very long shot:

is there any way to amend appended text on a label? 

I have hit an area where I would like to find a solution of some kind.

The label gets appended as the game progress and can be appended in any order.

They is much that will be added (appended) to this one Label.

Example of an append:  "Need to find oil." On finding oil changes to:  "Have found oil."

Perhaps there is a better way to display this information?

cheers



Joe

#1
Store your appended text in a variable.
Note the code below will actually be pseudocode:
Code: ags

String base_text="whatever";
String appended_text="Need to find oil";
label.Text=String.Format("%s %s",base_text,appended_texd);
//Amend the append:
appended_text="Have found oil";
label.Text=String.Format("%s %s",base_text,appended_texd);


It doesn't cover all your purposes but I think it can help you to figure out the solution.
Copinstar © Oficial Site

Slasher

#2
Hi,

very useful Joe (nod)

However, I need to know that I am on the right track.

This is what I have done so far and it works with the first 2 variables:

Created a function in new Script: Label_Manager() (Label_Manager.asc)

import function Label_Manager(); (Label_Manager.ash)

Created variable: Label_Text

Added variables to function Label_Manager()

as such:

Code: ags


function Label_Manager(){
 
 if(Label_Text==1){
   String base_text="[Need to find lubricant for Puppet Boy.";
   String appended_text=("[I have found lubricant for Puppet Boy");
   appended_text="[I have found lubricant for Puppet Boy";
   LMemory.Text=String.Format("%s",base_text);
   }
 else if(Label_Text==2){
   String base_text="[Need to find lubricant for Puppet Boy.";
   String appended_text=("[I have found lubricant for Puppet Boy");
   appended_text="[I have found Lubricant for Puppet Boy.";
   LMemory.Text=String.Format("%s",appended_text);
// I am certain I do not need all lines in both the above.
  }
  }
 


At the correct point to add:

Code: ags

// At the point when this needs to be:

 Label_Text=1; // Variable to run
 Label_Manager(); // to update variable string

// To update later when Lubricant is found:

 Label_Text=2; // Variable to run
 Label_Manager(); // to update variable string


Could those in the 'know' please give me a helping hand to bring this to fulfilment?

cheers



Joe

Well 1st of all: using a global variable (label_text) within a function is not elegant, do it if there is no other possibility. In this case you should define the "function Label_Manager()" as "function Label_Manager(int Label_Text)" and whenever you call that function you specify the parameter e.g.:Label_Manager(1);
Also, as you say you can declare the strings outside the "if" so you can control them in the whole function.
Code: ags

function Label_Manager( int Label_Text ){
 String base_text="[Need to find lubricant for Puppet Boy.";
 String appended_text=("[I have found lubricant for Puppet Boy");
 if(Label_Text==1){
   appended_text="[I have found lubricant for Puppet Boy";//I dont understand these lines since your are not really modifying anything.
   LMemory.Text=String.Format("%s",base_text);
   }
 else if(Label_Text==2){
   appended_text="[I have found Lubricant for Puppet Boy.";
   LMemory.Text=String.Format("%s",appended_text);
  }
}


Apart from that, looking at your new code makes me feel a bit confused and now I dont know what's your current purpose.
Lets guess your goal is having a label which shows something like this:

-Go to supermarket
-Find oil
-Get some cookies
-Drop some water


And whenever any of these missions are completed it should show:

-Go to supermarket
-Have found oil (mission completed)
-Get some cookies
-Dropped some water (mission completed)


In that case it's a bit more complicated. Tell me wether this is your purpose or not.
Copinstar © Oficial Site

Slasher

Hi Joe,

right...

All happens in one label: LMemory

Can be done in any order (there is quite a few)

First problem: Find lubricant.
Second problem: Find food.
Third problem: Find something to light up bulb

In any order

Solved First problem: text changes to: Have found lubricant
Solved Second problem: text changes to: Have found food
Solved Third problem: text changes to: Have found battery

This is what I am trying to achieve.

Similar to your example.

Cheers


Joe

#5
Ok this is what I have in mind to reach your goal.

Code: ags

//Your script asc
#define MAX_MISSIONS 100
String missions[MAX_MISSIONS];
int mission_count=0;
function AddMission(String mission_text)
{
  missions[mission_count]=mission_text;
  mission_count++;
  return mission_count-1;//return the mission ID
}
function ModifyMission(int missionID, String new_text)
{
  missions[missionID]=new_text;
}
function RefreshLabel()
{
  LMemory.Text="";
  int i=0;
  while(i<mission_count)
  {
    LMemory.Text=String.Format("%s %s [",LMemory.Text,missions[i]); //Maybe AGS has an append method, I can't remember
    i++;
  }
}

Code: ags

//Your script ash

import function AddMission(String mission_text);
import function ModifyMission(int missionID, String new_text);
import function RefreshLabel();



Then you could call these functions somewhere:

Code: ags

//At global position
int lubricant_mission,food_mission;

//When you want to add 1 mission or more
lubricant_mission=AddMission("Find lubricant.");
food_mission=AddMission("Find food");
RefreshLabel();

//Whenever you want to modify the text for mission completed:
ModifyMission(lubricant_mission,"Have found lubricant");
RefreshLabel();


This script can be impooved a lot but I think it's a good shot. Also it's not tested so you will surely find some syntax errors.
Copinstar © Oficial Site

Slasher

#6
Hi Joe,

going better.

At the moment:

Find Lubricant
Find food

but then

Found lubricant OK
Find food (after modifying) WRONG

It gets a little mixed up...

Still, its a possibility (nod)

I'm still working on it ;)

EDIT: With a bit of jiggling I appear to have it working and I also added a new mission that also works.

More tests before confirming mission 100% successful (laugh)

cheers Joe


Joe

Well. I just compiled it and works fine for me.
I forgot to mention that you have to export and import the oil_mission and food_mission variables.

EDIT: Ok posted right when you were editing. Glad you got it solved!
Copinstar © Oficial Site

Slasher

Hi,

I can confirm that the script Joe posted works.

Many thanks for helping me solve this issue (nod)

Mission completed.

Thanks Joe


Slasher

Hi,

(hope Joe see)

Adding missions is not a problem.  However, now I am modifying them it seems that add missions are being deleted when in another room

EG
Room 5
addmission
Room 6
addmission

Room 7
addmission
modifymission (this deletes an old add mission and still keeps modified and its add mission..

Could this be connected with the Refresh function?

SCRIPT:
Code: ags
//Your script asc
#define MAX_MISSIONS 100
String missions[MAX_MISSIONS];
int mission_count=0;
function AddMission(String mission_text)
{
  missions[mission_count]=mission_text;
  mission_count++;
  return mission_count-1;//return the mission ID
}
function ModifyMission(int missionID, String new_text)
{
  missions[missionID]=new_text;
}
function RefreshLabel()
{
  LMemory.Text="";
  int i=0;
  while(i<mission_count)
  {
    LMemory.Text=String.Format("%s %s [",LMemory.Text,missions[i]); //Maybe AGS has an append method, I can't remember
    i++;
  }
}
 


Code: ags
//Your script ash
 
import function AddMission(String mission_text);
import function ModifyMission(int missionID, String new_text);
import function RefreshLabel();
 


Code: ags
//At global position

//examples:

int lubricant_mission,food_mission;
 
//When you want to add 1 mission or more
lubricant_mission=AddMission("Find lubricant.");
food_mission=AddMission("Find food");
RefreshLabel();
 
//Whenever you want to modify the text for mission completed:
ModifyMission(lubricant_mission,"Have found lubricant");
RefreshLabel();
 



Actual Ints:
Code: ags

int  nursery_mission, radio_mission, clover_mission, head_mission, barn_mission,  spike_mission, wardrobe_mission, pit_mission, train_mission, carpet_mission, ladder_mission, madonna_mission, lubricant_mission, food_mission, word_mission, wheel_mission, battery_mission, glue_mission, elements_mission, switch_mission, questions_mission, block_mission, wooddoor_mission, combust_mission, direction_mission, cup_mission,balloons_mission,candle_mission,word2_mission;




Hope this can be sorted.

Cheers



SMF spam blocked by CleanTalk