I am trying to make a RPG game in IOS, with a similar dialogue system in Baldurs Gate. I have created two arrays in a plist file. Like this:
As you can see I have two arrays: PlayerMessage; a list (it will be) of multiple choices that the player can touch and NPCMessages; the text that is displayed when the PlayerMessage is touched
I am at the stage where I can touch on the NPC and see a black box with text from array (PlayerMessage). However I do not know how to tell Swift, if a player touches the string of the Item in PlayerMessage and if same item exist in NPC Message display the string of that item.
Here is the code that I have used:
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { for touch in (touches) { NPC.name = "NPC" let Location = touch.location(in: self) var CorrectedLocation = CGPoint() CorrectedLocation.x = Location.x - LocalCamera.position.x CorrectedLocation.y = Location.y - LocalCamera.position.y let node = self.atPoint(CorrectedLocation) var Message: SKLabelNode! Message = SKLabelNode(fontNamed: "Trebuchet MS") if (node.name == "NPC") { let NPCMessageer = SKSpriteNode (color: UIColor.black, size: CGSize(width:1000, height:1000)) NPCMessageer.zPosition = 99 NPCMessageer.position = CGPoint(x:-500, y:-200) Message.fontSize = 50 Message.color = UIColor.white; Message.position = CGPoint(x:-500, y:-100) Message.zPosition = 100 addChild(NPCMessageer) self.addChild(Message) for PlayerMessage in NPC.PlayerMessage { Message.text = PlayerMessage as?String} let label = self.atPoint(CorrectedLocation) if label.name == "Message" { if NPC.PlayerMessage == NPC.NPCMessage { Message.text = NPC.NPCMessage as?String }