ThePentiumGuy Posted January 11, 2005 Posted January 11, 2005 How woudl you use a GoTo command like in QBASIC, in VB.NET. For example: GotoPoint Beginning <-- I wish this existed msgbox("story") msgbox("more story") if msgbox("Woudl you like to repeat") = messageboxresult.Yes Then GoTo Beginning <-- I wish this existed end if (I'm not sure of the QBASIC syntax for "GotoPoint"). So is there any way to do this without creating your own functions -TPG Quote My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!) vbprogramming.8k.com My Project (Need VB.NET Programmers) http://workspaces.gotdotnet.com/ResolutionRPG
coldfusion244 Posted January 11, 2005 Posted January 11, 2005 How woudl you use a GoTo command like in QBASIC, in VB.NET. For example: GotoPoint Beginning <-- I wish this existed msgbox("story") msgbox("more story") if msgbox("Woudl you like to repeat") = messageboxresult.Yes Then GoTo Beginning <-- I wish this existed end if (I'm not sure of the QBASIC syntax for "GotoPoint"). So is there any way to do this without creating your own functions -TPG Ah good on QBasic ;) I believe in VB.NET it's Goto?? try this, it's been a long while since i've written VB...bare with me... Private Sub Test() dim a as long = 1 goto c: a = 1567 c: text1.text = a End Sub Should say a = 1. Quote -Sean
ThePentiumGuy Posted January 11, 2005 Author Posted January 11, 2005 Oh. See I enver tried this before ;) (this comp doesn't have .NET and the idea popped up just now). I'll give this a try. -The Pentium Guy Quote My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!) vbprogramming.8k.com My Project (Need VB.NET Programmers) http://workspaces.gotdotnet.com/ResolutionRPG
techmanbd Posted January 11, 2005 Posted January 11, 2005 Oh. See I enver tried this before ;) (this comp doesn't have .NET and the idea popped up just now). I'll give this a try. -The Pentium Guy That is how you do it. name where you want to goto followed by the colon sign as follows gotoheretostart: and then call for it goto gotoheretostart Will only work though, I believe in the same sub. Quote Live as if you were to die tomorrow. Learn as if you were to live forever. Gandhi
ThePentiumGuy Posted January 11, 2005 Author Posted January 11, 2005 Is there a way to "Declare" a goto ? I'm trying to do some scripting (to read dialogues) and I want to be able to go back and forth adn back and forth. Since it will be scripted, how am I supposed to.... oh man this all seems confusing now. anyone have some tips? I'm guessing my "dialogue" file will look like this: -say stuff PointA: -say more stuff ... this line will automaticall get split into 1 or more dialogue boxes ....etc... this line will get split. C: Yes, No, Repeat Conversation; Do you want some money? +Yes: Thank you for taking my money........ +No: JUST TAKE MY MONEY +Repeat Conversation: GoTo PointA -Thank you for talking to me See I have absolutely no idea how to get started. I don't even know if that's how I should approach the text file. Any tips? -The Pentium Guy Quote My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!) vbprogramming.8k.com My Project (Need VB.NET Programmers) http://workspaces.gotdotnet.com/ResolutionRPG
ThePentiumGuy Posted January 12, 2005 Author Posted January 12, 2005 (edited) After sitting down for about 30 minutes, I got this: Dialogue.txt Hi. I'm some guy. Here is the story of my life. Blah blah blah blah blah. Choice:2,Yes,No:Would you like some money? #Choice Yes: 2 Here's some money Do whatever you want with it. No: 2 Fine, be that way. Go away. #EndChoice Go Home This works like so: "Hi I'm some guy" "Here is the story of my life. Blah blah blah blah blah." "Would you like some money" <Choose Yes> "Here's some money" "Do Whatever you want with it" "Go Home"OR "Hi I'm some guy" "Here is the story of my life. Blah blah blah blah blah." "Would you like some money" <Choose No> "Fine, be that way." "Go away." "Go Home"I have no idea how to read something like this (above) and parse it. I could first try: If you wish to see the code in a much more orderly fashion, please visit http://www.xtremevbtalk.com/showpost.php?p=922655&postcount=1 and scroll down. The VB tags are messed up on this forum. line = reader.readline If Not line.contains(":") Then 'Read it like normal 'This is easy Else s =line.split(":") if s(0) = "Choice" then LookAtChoice(line) End If End If Public Sub LookAtChoice(line as string) Dim colonSplit() as string Dim commaSplit() as String Dim numberofchoices as integer colonsplit = line.Split(":") 'Split "Choice:Yes,No:Would you like some money?" texttodisplay = colonsplit(2) ' "Would you like some money" commasplit = colonsplit(1).Split(",") numberofchoices = commasplit(0) ' I'll create a DisplayChoiceList function somewhere else. ' The game will only be able to hold 2, 3, or 4 choices if numberofchoices = 2 then DisplayChoiceList(numchoices, commasplit(1), commasplit(2)) if numberofchoices = 3 then DisplayChoiceList(numchoices, commasplit(1), commasplit(2), commasplit(3)) if numberofchoices = 4 then DisplayChoiceList(numchoices, commasplit(1), commasplit(2), commasplit(3), commasplit(4)) UpdateTextToDisplay() End Sub 'Later, when the player chooses a choice: Public sub CheckForChoices(myChoice as String) Reader.readline() 'The #Choice line is just for cleansiness Dim numLines as string loop until reader.readline = myChoice & ":" 'The line looks like " Yes: " numlines = cint(reader.readline) ' the 2 in the line after Yes: .. or No: for x as integer = 1 to numlines texttodisplay = reader.read UpdateTextToDisplay() next Loop until reader.readline = "#EndChoice" 'Skip the rest of the choices Wend Wend End Sub By the way, that's pseudocode(this was originalyl a post I made in Xtreme VB Talk). So please excuse any errors. Do you guys think that this will work? Now about GoTo, I figured it out. to GoTo a place in the text: Close the file open the file loop until you get to that place. Please post any input. As well as anything you see that might go wrong (ex: Nested Choices...etc) -The Pentium Guy Edited January 12, 2005 by ThePentiumGuy Quote My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!) vbprogramming.8k.com My Project (Need VB.NET Programmers) http://workspaces.gotdotnet.com/ResolutionRPG
coldfusion244 Posted January 12, 2005 Posted January 12, 2005 By your psuedo code above.... I gathered this. I'm not sure if it's what you wanted... Yeah my VB is horrible, so be nice... Private Sub Greet() dim strLastStage as string = "Intro" dim strResponse as string = "" Intro: Print "Hi, I'm some guy." strLastStage = "Intro" MakeDecision: Select Case strLastStage Case "Intro" 'Main Decision Branching strResponse = DisplayChoiceList() If strResponse = "MoneyYes" strLastStage = "MoneyYes" ElseIf strResponse = "MoneyNo" strLastStage = "MoneyNo" ElseIf strResponse = "Intro" Goto Intro: Else strLastStage = "End" End If Goto MakeDecision:'Call itself again to select correct course of action Case "MoneyYes" Print "Here's some money" Print "Do whatever you want with it." strLastStage = "Intro" 'Set back to intro to have more decisions come up Goto MakeDecision: 'See above Case "MoneyNo" Print "Fine, be that way." strLastStage = "Intro" 'See above Goto MakeDecision:'See above Case "End" Print "Bye!" 'Don't do anything, the conversation has ended and the Sub will exit End Select End Sub Quote -Sean
Himo Posted January 12, 2005 Posted January 12, 2005 Why use Goto in the first place? We're in the age of OO programming :rolleyes: Goto is bad programming and makes your code less readable, don't use it. I think this could be a OO solution(My VB might be incorrect) Dim Questions() As String(5) Dim Answers() As String(5) Dim NpcAnswers() As String(5) Public Sub Main(Blah) Questions(0) = New String("Want some money?") Answers(0) = New String("2/Yes/No") NpcAnswers(0) = New String("2/Fine, leave it that way then./Okay, here you have some.") Conversation(Questions, Answers, NpcAnswers) End Sub Public Sub Conversations(Questions() As String, Answers() As String, NpcAnswers() as String) Dim index As Short Dim x As Short Dim answercode As Short Dim temp() As String For index = 0 To questions.Size 'Or whatever //Display question(index) temp = Answers.Split("/") For x = 0 To temp.Size //Display x: Answers(index) Next x answercode = Convert.ToInt16(Reader.readline()) //Display NpcAnswer(answercode) Next index End Sub A lot more civil I think so. Quote For questions about VS .net extensibility, please fire at me! :) For readability, please use the [ CS][/CS ] tags
IngisKahn Posted January 12, 2005 Posted January 12, 2005 Let me second the motion. Except in the rarest of situations (like emulating the continue keyword in C, whick I think they added in VB.NET 2.0) you should never use Goto. If, Do/Loop, For, For Each, and Select Case can always get the job done and they make the code much easier to read. Quote "Who is John Galt?"
ThePentiumGuy Posted January 12, 2005 Author Posted January 12, 2005 Thanks for the advice on GoTo. I'll have a look at each of your code. Coldfusion, I don't think your "manual" method will work because I want it to be scripted (read from a textfile). Thanks anyways. Heh, Himo, you used ' as a VB comment then immediately switched to C# style comments ;). Thanks a lot guys, I'll need to copy the code onto a floppy to my computer with .NET (No internet). I'll give it a try and get right back to you. -The Pentium Guy Quote My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!) vbprogramming.8k.com My Project (Need VB.NET Programmers) http://workspaces.gotdotnet.com/ResolutionRPG
ThePentiumGuy Posted January 13, 2005 Author Posted January 13, 2005 The best way which I found was to use an INI Parser (Thanks to Faith at XVBT) An INI has sections like this: [beginning] [Middle] [End] And in the INI parser (I forgot the exact API name), you can change the section name. If anyone would like more info, you can check out: http://www.xtremevbtalk.com/showthread.php?p=924066#post924066 -The Pentium Guy Quote My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!) vbprogramming.8k.com My Project (Need VB.NET Programmers) http://workspaces.gotdotnet.com/ResolutionRPG
Himo Posted January 14, 2005 Posted January 14, 2005 Hmm, yes, good old Ini's. But remember, that's legacy programming(API use) so it might not work in future versions of .NET/Windows Quote For questions about VS .net extensibility, please fire at me! :) For readability, please use the [ CS][/CS ] tags
coldfusion244 Posted January 14, 2005 Posted January 14, 2005 Hmm' date=' yes, good old Ini's. But remember, that's legacy programming(API use) so it might not work in future versions of .NET/Windows[/quote'] Not to sound like a mean person Himo, but if they cut out API use [say just for INI] in the next release of windows... alot of people would be very angry when many programs wouldn't work... Expecially most games that use INI's... So while I do share the enthusiasm for moving ahead, I also love API and don't think it'll just vanish in the next release. Speaking of which it takes them 3 years in between releases [about that], so being good for the next 6 years isn't bad for a program... Quote -Sean
Administrators PlausiblyDamp Posted January 14, 2005 Administrators Posted January 14, 2005 MS have no plans to remove the Windows API or prevent it to be called - that would be suicide in terms of getting people to adopt their newer platforms. They have however stated a desire to depreciate the use of APIs in favour of newer technologies (Avalon, WinFS, Indigo etc) in future windows releases. Certain APIs may no longer be supported for other reasons however (move to 64bits being one, security another). As a general rule for new projects it pays to look at current / near future technologies and see if they are suitable replacements for older methods; for legacy projects this kind of major upgrade is often not worth the cost - existing technologies will need to be supported. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
IngisKahn Posted January 14, 2005 Posted January 14, 2005 The biggest reason not to use it is because we're using .NET Using the API would not be CLR compliant. Quote "Who is John Galt?"
ThePentiumGuy Posted January 14, 2005 Author Posted January 14, 2005 But .NET doesn't have any way to parse INI files. "MS have no plans to remove the Windows API or prevent it to be called" thank you GOD. -TPG Quote My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!) vbprogramming.8k.com My Project (Need VB.NET Programmers) http://workspaces.gotdotnet.com/ResolutionRPG
Himo Posted January 14, 2005 Posted January 14, 2005 That's why I said 'might'. Not in Longhorn, but in the version thereafter, they might have a complete new system for API, INI and offcourse the registry. The registry is just one big mess and they for sure will remove it. No biggie here. The Api code from VB 6 must already be converted because it expects pointers and 32-bit values. Maybe the new versions of Visual .net will only support 64-bit kernel commands. And ini should be replaced by XML, but that's personal. Quote For questions about VS .net extensibility, please fire at me! :) For readability, please use the [ CS][/CS ] tags
coldfusion244 Posted January 14, 2005 Posted January 14, 2005 What's wrong with pointers, they are nice and fast :D .NET programs are quite slow I have found... Quote -Sean
IngisKahn Posted January 15, 2005 Posted January 15, 2005 Uh not really. It's easy to code them slow, but if you know what you're doing then speeds are nearly 100% equal to C++. If this wasn't the case then we could not use it at work. Quote "Who is John Galt?"
ThePentiumGuy Posted January 15, 2005 Author Posted January 15, 2005 Lol. Guys. He said version after longhorn. That's not going to come out until 2010 or something. Longhorn was supposed to be released in like 2004 now it's being pushed till 2006 (and somehow I feel it'll come out in 2007). That'll buy me some time to patch up stuff :), about 5 years. -TPG Quote My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!) vbprogramming.8k.com My Project (Need VB.NET Programmers) http://workspaces.gotdotnet.com/ResolutionRPG
IngisKahn Posted January 15, 2005 Posted January 15, 2005 But why not use the built in functionality? It's very simple and it supports hierarchal data, which, I think, would be useful in your case. Quote "Who is John Galt?"
ThePentiumGuy Posted January 15, 2005 Author Posted January 15, 2005 Is there a built-in INI parser for .NET? Or must I stick to the typical StreamReader? -TPG Quote My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!) vbprogramming.8k.com My Project (Need VB.NET Programmers) http://workspaces.gotdotnet.com/ResolutionRPG
IngisKahn Posted January 15, 2005 Posted January 15, 2005 I was implying using .config files and the Configuartion namespace. Quote "Who is John Galt?"
ThePentiumGuy Posted January 16, 2005 Author Posted January 16, 2005 I'll look into that. Thanks. -TPG Quote My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!) vbprogramming.8k.com My Project (Need VB.NET Programmers) http://workspaces.gotdotnet.com/ResolutionRPG
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.