index parameter limit 
	 
	
		| Author | 
		Message | 
	 
		 
		maincharName
 
 
 
    
		 | 
		
		
			
				  Posted: Thu Mar 23, 2006 9:08 pm    Post subject: index parameter limit  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				Is there a way to use more than two parameters with the find pattern in string function? I want to do this incase the variable response contains a variation of the word "take", like "get" or "pick up". 
 
 
I can get around this, but I'd be making a helix of 'if' statements to match the complexity of human DNA.
 
 
I was told last week that the register function should work, but I can't find any information on it.
 
 
Also, please keep in mind that I just started programming a week and a half ago. | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
		 
		Sponsor Sponsor 
		 
  
		 | 
		
 | 
	 
	 
		  | 
	 
				 
		person
 
 
 
    
		 | 
		
		
			
				  Posted: Thu Mar 23, 2006 9:13 pm    Post subject: (No subject)  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				| Write one if statement in a function, and then reuse that function | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		maincharName
 
 
 
    
		 | 
		
		
			
				  Posted: Thu Mar 23, 2006 9:19 pm    Post subject: (No subject)  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
					  | code: | 	 		  var response: string
 
loop
 
get response: *
 
if index ( response, "take" ) not = 0 then
 
  if index ( response, "key" ) not = 0 then
 
  put "You have taken the key."
 
  exit
 
  else
 
    put "There is only one attainable object in this room, and that is a key."
 
  end if
 
else
 
  put "What do you want with the key?"
 
end if
 
end loop  | 	  
 
 
That would work, but only if every time someone wanted to take something it was a key. This would be used within many different instances within a text-based game. | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		person
 
 
 
    
		 | 
		
		
			
				  Posted: Thu Mar 23, 2006 9:21 pm    Post subject: (No subject)  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				Use parameters.
 
 
	  | code: | 	 		  
 
fuction stuff (item1:string)
 
      put item1
 
end stuff
 
  | 	 
  | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		maincharName
 
 
 
    
		 | 
		
		
			
				  Posted: Thu Mar 23, 2006 9:41 pm    Post subject: (No subject)  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				| I'm sorry for not being more clear. What I wanted was to search the string variable 'responce' for "take", "get", and "pick up" and knowing that there is at least one of these words within the variable 'responce' then I can go ahead and search for the items. | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		maincharName
 
 
 
    
		 | 
		
		
			
				  Posted: Thu Mar 23, 2006 10:09 pm    Post subject: (No subject)  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				| I'm signing off, thank you anyway. | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		chrispminis
 
  
 
    
		 | 
		
		
			
				  Posted: Fri Mar 24, 2006 12:32 am    Post subject: (No subject)  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				Hmm, if I'm interpreting your question right, you speak of how to recognize all variations of a word without repetitive coding. Variations such as "key", "Key", "kEY", etc?
 
 
If so, the solution is simple. Do your regular check but right before that, convert the entire string to lower or upper case using Str.Lower or Str.Upper. Here is the adjusted code.
 
 
	  | code: | 	 		  var response: string
 
loop
 
get response: *
 
response := Str.Lower (response)
 
if index ( response, "take" ) not = 0 then
 
  if index ( response, "key" ) not = 0 then
 
  put "You have taken the key."
 
  exit
 
  else
 
    put "There is only one attainable object in this room, and that is a key."
 
  end if
 
else
 
  put "What do you want with the key?"
 
end if
 
end loop
 
  | 	 
  | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		Delos
 
  
 
    
		 | 
		
		
			
				  Posted: Fri Mar 24, 2006 10:30 am    Post subject: (No subject)  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				That's a good approach - however, it doesn't cover the possibility that 'take' is synonymous to 'get'.  (So if the User typed "get kEY" or "take KeY", then the resultant action would be the same.  Why the random case-shift?  No reason  ).
 
 
Ok, so what we're getting at here is having a dictionary of commands that can be used for various actions.  Certain actions have several unique identifiers associated with them.
 
Let's continue with your example of picking up a key.  We have a key present in the environment, and the User wishes to retrieve it.  They may use:
 
- pick up
 
- get
 
- take
 
And likely more.  We'll leave it at three for now.
 
 
The User inputs a command string.  Let's say it's "get key".  We now want to parse this and determine whether a command exists.  Since we have several command-phrases relating to the same command, we can just cycle through each of them checking them against the inputted string.
 
 
So:
 
	  | code: | 	 		  
 
% Pseudo code!
 
declare:
 
  response (string)
 
  action_get (array: {"pick up", "get", "take"})
 
 
input:
 
  get response
 
 
parse:
 
  for i : 1 to upper bound of action_get
 
    if action_get (i) is in response then
 
      perform_action_get
 
  end
 
  | 	  
 
 
Simple eh?  The challenging part of this will be streamlining it so that you can easily reference your commands.  It is about this point that you'll want to start incorporating fcns.
 
A little used aspect of records is their ability to hold fcns/procedures etc.  This is a little limiting in that the specified fcn structure and the one to be used must match directly.
 
 
	  | code: | 	 		  
 
fcn hello1 () : string
 
   result "Hello World"
 
end hello1
 
 
fcn hello2 (inStr : string) : string
 
   result "Hello World, " + inStr
 
end hello2
 
 
type greet :
 
   record
 
      name : string
 
      FCN : fcn hello () : string
 
   end record
 
 
var test : greet
 
test.name := "Oboro"
 
test.FCN := hello1
 
% test.FCN := hello2
 
% This will crash due to incompatability of fcns.
 
 
put test.FCN (), ", ", test.name
 
  | 	  
 
 
You can use this idea to compartmentalise the various actions in your proggie. | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
		 
		Sponsor Sponsor 
		 
  
		 | 
		
 | 
	 
	 
		  | 
	 
				 
		 | 
	 
 
	
	
	 
	
	 |