Haha. Neither can I really. But I hope you see that there's very little difference between the two codes
I'm not sure how to setup a proper trigger to dump the input line into a variable though..
I do plan on putting a Hotkey in my GUI code so that when the user types something and presses the Enter key, I want it to capture whats in the String Gadget and put it into a variable called "Input$" or some such thing.
That's exactly the way it needs to be done.
Wait for a trigger-event (either Hotkey, or button nearby) and simply store it in a variable, or in a list, so that you can use Cursor-Up to iterate through the list. I find that function extremely useful in the windows cmd.
Oh, there was a typo. Cursor-Up, search and correct typo, enter. Tadaaa.
Saves a lot of time when dealing with complex commands.
Just an idea for you
GetGadgetText() is the function for that.
You can split the string by any delimiter you like (including Space, ofcourse). Use
StringField()
For SelectElement() you'd have to know the exact position of the object in the list. So that's most of the time not an option (it defies the use of a linked list. If I wanted to get to entries by calling their position, I would use an array).
I'd do it like this:
Upon entering the room you create (or clear for every room but the first one (first one being the room you're starting after loading a save-file. Not necessarily the room you start the game in)) a list of all the objects in this room and the inventory of the player.
Then you find the command, you'll actually use.
Use a map for this.
Code: Select all
NewMap commands.s()
commands("wear") = "equip"
commands("equip") = "equip"
commands("attack") = "attack"
commands("fight") = "fight"
.
By simply calling
commands( token_1 ), you know the player wants to equip an item.
Now you iterate through that list of objects in the room (it's a very small list of maybe max. 10 objects?)
Code: Select all
Foreach ObjectsInRoom()
If ObjectsInRoom()\name = token_2
ObjectsInRoom()\parent = playerUID ;
Endif
Next
Alternatively you could do something like this. It's even better, but it only works with equip. If he want's to put something down/in a chest... you should simply change the parent.
Code: Select all
Foreach ObjectsInRoom()
If ObjectsInRoom()\name = token_2
Equip(ObjectsInRoom()\UID) ;
Endif
Next
Where Equip looks like this:
Code: Select all
Procedure Equip(id.i)
If slot_1 = 1
If slot_2 = 1
If slot_3 = 1
ProcedureReturn #False ;No slot available: "You can't equip whatever, because you have no empty slots...."
Else
slot_3 = id
EndIf
ProcedureReturn #False ;No slot available: "You can't equip whatever, because you have no empty slots...."
Else
slot_2 = id
EndIf
ProcedureReturn #False ;No slot available: "You can't equip whatever, because you have no empty slots...."
Else
slot_1 = id
EndIf
ProcedureReturn #True
EndProcedure
You see I used 3 lines instead of only 1.
Because I wanted to know
which of the slots is empty.
The necklace is placed in the first empty slot.
[X][X][ ] -> [X][X][O]
[ ][X][ ] -> [O][X] []
[X][ ][ ] -> [X][O][ ]
etc...
So at this time (Equip() returns #True) you delete the necklace from the List of Objects in the Room.
Upon leaving the room you iterate through the whole list of all Objects (you need to do that anyway to build the list for the next room) and you change the parent of the necklace from roomX to players_inventory.
I'm guessing optional values would have to be on the end of the syntax ? Can you skip a value at all if it isn't present? If so, how?
Code: Select all
Procedure test(mandatory1, mandatory2, optional1=0, optional2=99)
Debug mandatory1
Debug mandatory2
Debug optional1
Debug optional2
EndProcedure
test(1, 2)
test(1, 1, 1, 1)
test(1, 1, 1)
test(1, 1, 0, 1)