menu systems and functions
Displaying 1-8 of 8 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
aazami

I was looking into the coding for sully's menu system... zomg i dont get most of it. I wanted to know how would i go about having the code pause for user selection. I also need to understand how the code tree works in verge i mean you have a menu system file then a system file and ect; can i pull functions from anywhere in anyfile? is the "callfunction" a preset thing for verge of do i have to create it myself? and what is with the functions that are like func( variable, " ") qutation marks? what? also how do you write and read from a dat file in verge. also in what order do i do things in verge to get things working i mean you have to load files first so that everything can be written on screen? so i have a set of letters (font.png) how do i get to display each individual letter in that one file in the order i want? just with an img file I saw it is possible, is there a size limit i should know of or take into account when i am coding the display of letters? so if i type out a string of dialog in notepad coding that it will display in its font and location <-- how do i do that as well. is there a way to tell what are the cords are on screen where it will display before i write the code and guess where the img will display? for example 53,24 is at this location and will display on your screen here. what are the end of screen right. left, top, bottom cords?
int MenuControlArrows(int value, int limit)
{
if (up || left)
{
if (lastpress + MENU_PRESS_DELAY < timer)
{
value = (value - 1 + limit) % limit;
lastpress = timer;

CallFunction(_m1ASnd); //call the sound function defined with Menu1ArrowSetSounds()
}
}
else if (down || right)
{
if (lastpress + MENU_PRESS_DELAY < timer)
{
value = (value + 1) % limit;
lastpress = timer;

CallFunction(_m1ASnd); //call the sound function defined with Menu1ArrowSetSounds()
}
}
else lastpress = 0;
return value;
}
what is the time % stuff for? i dont get that. where is time declared? would it be fine to make it like if button is pressed play sound, instead of all this calulation? what is going on here?

Posted on 2008-07-08 20:58:19 (last edited on 2008-07-09 23:56:00)

Overkill

I don't entirely understand what you're asking, but I tried my best to answer everything. (I originally was being a big jerk, I apologize ;_; Hopefully this info's more helpful.)

The sully codebase is big, and you're not meant to read ALL of it. As with any big volume of code, it's usually quite scarring and confusing to look at.

Quote:Originally posted by aazami

can i pull functions from anywhere in anyfile?
You can pull functions that you declare from any file, by using an #include directive. This is explained in both tutorials and the manual.

Quote:Originally posted by aazami

is the "callfunction" a preset thing for verge of do i have to create it myself?
Yep, CallFunction is a function that is built in to Verge. Its use is sort of advanced. Unless you have a use for it or are required to use it in a library of some sorts, I'd stick with just calling functions directly instead of through CallFunction.

Though it's useful! It allows you customize events by switching in other functions at runtime by just switching a string around.

Quote:Originally posted by aazami

what is with the functions that are like func( variable, " ") qutation marks? what?
It depends, really! Functions can take any sort of parameters you want! Quotations are for strings! (ie. text, names, descriptions for things, other textual things like that).

Your best bet is to either find where the function is declared and see how each parameter is used. Also, check the manual for a list of the builtin functions (which won't be declared anywhere except in verge.exe itself), which is pretty handy. At any rate, each of those variables and strings and numbers in a function call has a use specific to that function.

Quote:Originally posted by aazami

also how do you write and read from a dat file in verge.
Using the file functions, listed in the manual. You'd use FileOpen to open the file, then you'd use a bunch of those crazy FileRead___ / FileWrite___ functions. Sully has their own dat formats and stuff for their system.

Really .dat is just a file extension, a dat file could be filled with any sort of information you want to put in a file! If you have a specific dat format you want to be able to read, I can explain how to use it. I don't know too much about Sully's dat files, but I'm sure Grue knows a fair deal.

Quote:Originally posted by aazami

also in what order do i do things in verge to get things working i mean you have to load files first so that everything can be written on screen?
You can load resources like images/fonts/sprites whenever, you just gotta load them in before you draw them to the screen. You do that by calling LoadImage/LoadFont/whatever and storing them in a variable before you actually use the resource with a Blit() or PrintString() in a loop.

Quote:Originally posted by aazami

so i have a set of letters (font.png) how do i get to display each individual letter in that one file in the order i want? just with an img file I saw it is possible, is there a size limit i should know of or take into account when i am coding the display of letters?
I'd probably recommend looking at other working font images. This is the layout of the characters you need to follow. There isn't any size limits on individual characters, just remember to make your individual cells (boxes) in the font all the same size. This also does a good job of explaining fonts.

Quote:Originally posted by aazami

so if i type out a string of dialog in notepad coding that it will display in its font and location <-- how do i do that as well.
Fonts are loaded into your game by using LoadFont. Printing text onto the screen is done with PrintString.
int font = LoadFont("font.png");
PrintString(5, 5, screen, font, "Here be some text!");


Quote:Originally posted by aazami

is there a way to tell what are the cords are on screen where it will display before i write the code and guess where the img will display? for example 53,24 is at this location and will display on your screen here. what are the end of screen right. left, top, bottom cords?
Sure, 0, 0 is the left top corner, so increasing the x is moving right, increasing y is moving down. The resolution of your game window determines where the bottom-right of the screen are, which you can get by ImageWidth(screen) and ImageHeight(screen) to figure out where the right bottom corner is.

Quote:Originally posted by aazami

what is the time % stuff for? i dont get that. where is time declared?


The % sign there is for silly, shortcuts instead of multiple if statements. The % means modulo, which is the remainder of division. Any expression x % y is basically a fancy way of keeping the value "x" between the numbers 0 and y-1, which lets you do funky stuff like wrap the cursor around when you move up at the top of a menu.

timer is a built in variable, so it's declared inside verge.exe itself, rather than VC files. You can read about builtins in the manual! They use it here to remember the last time a key was pressed, and if it's being held for a while it'll repeat the press (move up again automatically after you hold it down for long enough)

Quote:Originally posted by aazami

would it be fine to make it like if button is pressed play sound, instead of all this calulation? what is going on here?
Yeah, it is pretty complicated to read to any person starting off, but really it isn't too bad. That function is basically just used to move the cursor when an arrow key's pressed, and it has a thing so the cursor will repeat after so many seconds, hence the timer.

And it does play sounds when you move the cursor, you just need to set it with the Menu1ArrowSetSounds function in the Sully code I guess.
CallFunction(_m1ASnd); //call the sound function defined with Menu1ArrowSetSounds()


The callfunction magic there is to call a function that actually plays the sound effects. _m1ASnd could be a string like "PlayCursorBlip" which is the name of our function PlayCursorBlip which makes sounds or something.
void PlayCursorBlip()
{
PlaySound(sound_blip, 100);
}


Edit: updated to hopefully be more helpful and less of a jerk. Sorry. :(

Posted on 2008-07-09 23:52:16 (last edited on 2008-07-10 16:33:09)

mcgrue

Wow, overkill.

...That's not exactly how I'd've answered that question.

aazami, the sully menus are not coded in the best possible way. I don't know what the best possible way is. The way they're currently made is to have a concept of "pages", and a function that updates a page's control and a function that draws the page.

I wanted to have the control loop for the menu in one place, instead of passing the render baton all over the place.

It's got a few concepts to grasp, and isn't "beginner" code, but you could get the gist of it after a few smaller adventures in scripting, if you are a beginner.

If you have any ideas for what would be a saner system for making menus, I'm very open to suggestion.

Posted on 2008-07-10 02:26:28

Overkill

Hm you're right, that was pretty harshly worded of me. Sometimes I'm a jerk, supersorry aazami. :(

(Also: I just noticed Rysen's tutorial seems to be down today. ;_;)

Edit: modified other post to sound like less of a jerk.

Posted on 2008-07-10 16:08:42 (last edited on 2008-07-10 16:30:25)

glambourine

Here's some actual code that you can adapt, use as a shell, study whatever without having to wade through the complexity of Sully and its discontents.

To pause the code for user selection essentially do this:

blah = 0;

while (!blah) {

dowhatever();
showpage();

if (b1) { blah = 1; }

}


where "blah" is just some arbitrary variable, dowhatever() does whatever you want it to do, showpage() updates the screen and the keyboard/mouse variables, and b1 is one of VergeC's button variables (I think it defaults to the enter/return button.) Showpage checks if the b1 key is pressed and writes whether it's pressed or not to the virtual variable b1. (I think that's how it works?) As soon as you press b1, you're done, so the code breaks out of the loop. This solution probably has a gazillion things wrong with it but it'll at least get you started with coding stuff that involves user input.

Reading and writing from files I do like this:

int file_pointer; // a variable that'll represent the file
string s; // a variable to represent the things we yank from the file

file_pointer = FileOpen("items.dat", FILE_READ); // we use
FileOpen to open the .dat file, then send the location of the
opened file to file_pointer. FILE_READ means that we're reading
from the file, not writing to it

while (!FileEOF(file_pointer)) { // while there's still data in items.dat

s = FileReadLn(file_pointer); // take one line of data from
items.dat and throw it into our string variable

DoThingsWith(s); // one of our own functions
for terrible purposes

// filereadln() automatically increments the file position so
we'll eventually break out of the loop

}

FileClose(file_pointer); // it's only polite


Again, there are problems with this, but it's the simplest way to just go through a file one line by one and do things with the data inside. If you're going to work with .dat files I seriously recommend reading up on all of the string functions in the Verge3 manual, especially left(), mid(), str() and val().

All of these have huge issues but will at least show you the basic logic you've got to use within the arcane Verge3 system. I don't get the timer stuff either yet and just try to avoid it, which is not a good long-term strategy but really, you have better things to worry about when you're just starting out with this VERGE thing.

Posted on 2008-07-10 23:24:47 (last edited on 2008-07-10 23:29:46)

Overkill

Well, let me explain the timer stuff. timer and systemtime both automatically count up 100 times every second. timer can be written to, whereas systemtime can't. You never really need to write over the timer, but you can!

At any rate, if you have a timed event, like waiting a couple seconds mid dialog, you'd you'll wanna use a timer, so that the wait time specified is the same on any computer running your game.

So let's make a function that does exactly that. I'm using systemtime here, but it really doesn't matter, use timer if you want. They're identical in the fact that they both count up.
void Wait(int duration)
{
// Our time variable which will keep track of when the wait should be over
int timestamp;
// The ending time is the current time spot plus the duration we want to wait!
timestamp = systemtime + duration;
// As long as the current time is behind the "timestamp", keep pausing
while(timestamp > systemtime)
{
Render();
ShowPage();
}
}


So notice a little bit of oddness, if you read the timer or systemtime variable, it gives you the snapshot of what the timer value is at that time. If you store that in a variable or use it in an expression like above, it uses the snapshot in time when you get the value, and doesn't constantly update the variable you assign to.

Thus, you can store something like the current time elapsed + 5 seconds (or 500 'ticks' of the timer), and when the timer passes this marker you stored, you know 5 seconds have passed. You can also subtract the timestamp from systemtime, and you'll notice the difference shrinks and eventually becomes negative.

Using this shrink time difference though, you can do stuff like fade effects, where the darkness of the screen is related to how far along the fade is from "completing".

It might still be a little to digest there, but trust me, it's a handy thing to have under your belt. And figuring out the time lost between each frame is useful if you want to have realtime logic -- which is how you can synchronize action games and still have the logic itself done one tick at a time.

Don't fear timers, if you want:
1) ...an easy way to make your game events happen with the timing you want
2) ...the timing to be the same for everyone, regardless of computer specs
3) ...to let people use the fast forward key when your game is taking a ridiculous amount of time on some things and people are fed up :D

Posted on 2008-07-11 01:42:40 (last edited on 2008-07-11 02:21:40)

aazami

awesome! that helps alot, i just got so into it because my programming knowledge is limited to functions and arrays. im continuing school to get further into classes and databases. see how things are im trying to make a real time battle system along with a custom menu system so im learning this stuff now lol :) thanks for all the help :)

Posted on 2008-07-12 00:28:16

resident

I'm going to pimp shamelessly and suggest you take a look at my Pac-Stan demo. It's ridiculously simple code - certainly a lot easier to get started with than the full Sully codebase... and if you feel like adding a few maps while you're looking at it, that would be grand, too ;)

You might also take a look at Rysens Phoenix Flame demo if you want menu code. The last time I checked the game didn't compile under the latest version of Verge, but it's packed with a compatible EXE and it's the basic technique and nessecary interactions with the engine you want, not the wholesale code.

Generally speaking, for a menu, I'd use a similar system to a textbox. create a new integer function that pauses the entities, and create a new renderloop. Inside the renderloop, update the screen, then draw your menu on top like you would the textbox and get any player input. When the player presses a firebutton, exit the renderloop and pass the last menu option back to the main program in the integer, and set up a switch based off it for different menu options.

Posted on 2008-07-12 03:22:30 (last edited on 2008-07-12 03:27:11)


Displaying 1-8 of 8 total.
1
 
Newest messages

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.