 |
Castle Paradox
|
View previous topic :: View next topic |
Author |
Message |
Bob the Hamster OHRRPGCE Developer

Joined: 22 Feb 2003 Posts: 2526 Location: Hamster Republic (Southern California Enclave)
|
Posted: Tue Oct 14, 2008 9:26 am Post subject: |
|
|
You might also want to look at 'How do I store several tags in a variable?' it is tricky, because you have to know some binary math, but you can cram 16 tag-like pieces of data into the bits of a global variable.
Actually, that article is obsolete. Those scripts could be re-written to use all 32 bits of a global. |
|
Back to top |
|
 |
Kizul Emeraldfire Type: Cyber Dragoon

Joined: 26 Mar 2004 Posts: 229
|
Posted: Tue Oct 14, 2008 2:42 pm Post subject: |
|
|
Camdog wrote: | Why exactly do you think you'll need so many tags? 999 is quite a lot in my estimation, especially if you use the one-time-use tags for things like treasure chests.
For the record, you can use variables instead of tags. They'll have to be global variables, though, as local variables won't be saved. Checking them is as simple as writing their name; you don't need a special plotscript to do it. For example, if you have a global variable called 'foundTheMaguffin", you can update it like so:
Code: | foundTheMaguffin := true |
and check it like so:
Code: | if (foundTheMaguffin) then (#do something appropriate)
else (#do something else) |
The only problem with this is that custom has all sorts of built in ways of interacting with tags, whereas you'd need to use plotscripts to do any kind of checking or assigning with global variables. |
Well, I'm using them for things that I'm positive I won't be needing tags for. For example, for the ring-type menu I'm currently scripting, I'm using global variables for determining which item of the menu is currently selected. How I do it is, I use two unique NPCs, one is created eight times to show the menu items, and the other is created on top of the top-middle item as a selection cursor.
After the NPCs are created, I set the value of the selected menu item's (the top-middle one) global variable to 'TRUE', and all the other ones' to 'FALSE'. Then, when the player hits the left or right keys, the script rotates the main eight NPCs, checks their positions to see which one's in the top-middle position, then sets the global variables appropriately.
For my convenience, I have all the coordinates revolve around either the exact Hero Pixel X/Y, or Hero Pixel X/Y plus or minus 10 — it all appears around the hero walkabout sprite with a half-tile of padding between them.
James Paige wrote: | You might also want to look at 'How do I store several tags in a variable?' it is tricky, because you have to know some binary math, but you can cram 16 tag-like pieces of data into the bits of a global variable.
Actually, that article is obsolete. Those scripts could be re-written to use all 32 bits of a global. |
Thank you — even if it's outdated, it should be helpful.  |
|
Back to top |
|
 |
TMC On the Verge of Insanity
Joined: 05 Apr 2003 Posts: 3240 Location: Matakana
|
Posted: Thu Oct 16, 2008 11:18 pm Post subject: |
|
|
Kizul Emeraldfire wrote: | After the NPCs are created, I set the value of the selected menu item's (the top-middle one) global variable to 'TRUE', and all the other ones' to 'FALSE'. Then, when the player hits the left or right keys, the script rotates the main eight NPCs, checks their positions to see which one's in the top-middle position, then sets the global variables appropriately.  |
That seems really convoluted. Why don't you just store the number/npc reference of the currently selected items?
Most OHR games with pixel movement have broken collision detection: in fact, I can't think of a single game with perfectly working collision detection, not counting games like Baby Bob which only do collision with tiles.
You should not use 20x20 bounding boxes if your npcs/sprites are less than 20x20! This is the bit that everyone always gets wrong.
Camdog's collision detection script is on the ball. However, it's 4 times longer than it needs to be. Here's the shortened version (still operating on 20x20 bounding boxes):
Code: | #check for any npc collision, and run a script if applicable.
plotscript, check npcs, who, begin
variable(npcId, numRefs, curRef, i)
#loop through all possible NPC ids
for(npcId, 0, 35, 1) do(
numRefs := npc copy count(npcId)
for(i, 0, numRefs -- 1, 1) do(
curRef := NPC reference(npcId, i)
#collision detection
if ((npc pixel x(curRef) >= hero pixel x(who) -- 19) &&
(npc pixel x(curRef) <= (hero pixel x(who) + 19)) &&
(npc pixel y(curRef) >= hero pixel y(who) -- 19) &&
(npc pixel y(curRef) <= (hero pixel y(who) + 19)))
then(
if (read npc(curRef, NPCstat:script) >> 0) then(
run script by id(read npc(curRef, NPCstat:script), read npc(curRef, NPCstat:script argument))
)
)
)
)
end |
Many games seem to use objects in globals. I do something similiar to Camdog, with lots of runscriptbyid's for polymorphism. Looking at Eldardeen's scripts after working with C++ recently horrifies me. Thank goodness that when we add arrays it'll be 80% cleaner! I am also considering user defined types, though they wouldn't be much more than arrays. _________________ "It is so great it is insanely great." |
|
Back to top |
|
 |
Kizul Emeraldfire Type: Cyber Dragoon

Joined: 26 Mar 2004 Posts: 229
|
Posted: Fri Oct 17, 2008 8:13 am Post subject: |
|
|
The Mad Cacti wrote: | Kizul Emeraldfire wrote: | After the NPCs are created, I set the value of the selected menu item's (the top-middle one) global variable to 'TRUE', and all the other ones' to 'FALSE'. Then, when the player hits the left or right keys, the script rotates the main eight NPCs, checks their positions to see which one's in the top-middle position, then sets the global variables appropriately.  |
That seems really convoluted. Why don't you just store the number/npc reference of the currently selected items? |
D'oh! After reading what I said there a second time, I suddenly realize that it was wrong. It SORTA checks the NPC positions — but not by checking NPC pixel X/Y. Allow me to explain with a code snippet:
Code: | script, rotate clockwise, begin
#=- Shortly, this variable shall be used (and abused).
variable (rotate)
#=- First, check what's selected (starting from the 'Item' block,
#=- and moving counter-clockwise through the rest of the menu):
if (on_item == TRUE)&&(on_equip_menu == FALSE)&&(on_equip_spell == FALSE)&&(on_edit_targeting == FALSE)&&(on_save_menu == FALSE)&&(on_config == FALSE)&&(on_password == FALSE)&&(on_status == FALSE)
#=- Then, actually rotate the menu around -- the NPCs move at five
#=- pixels per tick; to slow it down, add more frames and change
#=- the X/Y shift amounts.
#=-
#=- Starting from the item in the top-left corner, going clockwise:
then (
for (rotate,0,6,1)
do ( # NPC Name: | Coordinate X: | Coordinate Y: | Comments:
put NPC (equip_menu, NPC pixel X (equip_menu) + 5, NPC pixel Y (equip_menu)) #=- Upper-left NPC and upper-
put NPC (item, NPC pixel X (item) + 5, NPC pixel Y (item)) #=- middle always move right.
put NPC (status, NPC pixel X (status), NPC pixel Y (status) + 5) #=- Upper-right NPC and right
put NPC (password, NPC pixel X (password), NPC pixel Y (password) + 5) #=- always move down.
put NPC (config, NPC pixel X (config) -- 5, NPC pixel Y (config)) #=- Lower-right NPC and low-
put NPC (save_menu, NPC pixel X (save_menu) -- 5, NPC pixel Y (save_menu)) #=- middle always move left.
put NPC (edit_targeting,NPC pixel X (edit_targeting), NPC pixel Y (edit_targeting) -- 5) #=- Lower-left NPC and mid-
put NPC (equip_spell, NPC pixel X (equip_spell), NPC pixel Y (equip_spell) -- 5) #=- left NPC always move up.
wait (1) #=- Sorry if this's hard to read.
)
on_item := FALSE
on_equip_menu := TRUE
on_equip_spell := FALSE
on_edit_targeting := FALSE
on_save_menu := FALSE
on_config := FALSE
on_password := FALSE
on_status := FALSE
)
#=- Lather, rinse, and repeat above (seven more times,
#=- moving TRUE down the line of globals as needed):
else (
if (# You get the picture now, I think. |
Excuse my indention style; it would look better if those were tabs instead of spaces.
To explain a little bit further: the main script starts off by creating some local variables, then spawns nine NPCs in a square around the main hero sprite; eight are eight copies of NPC 1 on the the map, and the other is one copy of NPC 0 (the cursor — it gets layered over the top-middle NPC 1 copy in the square). After that, it sets the local variables to NPC references, sets the Global variables to the values found in the top of the 'rotate (counter-)clockwise' scripts, sets the keypress script to the ring-menu keypress script that I'm making, sets a tag to allow the cursor to blink, and uses the cursor's 'blink' script before exiting.
The keypress script then calls either the Rotate Clockwise or the Rotate Counter-Clockwise script when either the right or left arrow keys (respectively) are pressed.
I'll probably have to change the local variables I'm using for the NPC references to Global Variables instead, though.
Anyway, when it's finished enough to do something, maybe I should post it here for critiquing?
The Mad Cacti wrote: | Most OHR games with pixel movement have broken collision detection: in fact, I can't think of a single game with perfectly working collision detection, not counting games like Baby Bob which only do collision with tiles.
You should not use 20x20 bounding boxes if your npcs/sprites are less than 20x20! This is the bit that everyone always gets wrong. |
I've never attempted to do collision detection before — thanks for the tip.
The Mad Cacti wrote: | Camdog's collision detection script is on the ball. However, it's 4 times longer than it needs to be. Here's the shortened version (still operating on 20x20 bounding boxes):
|
Wow, nifty! :o Now the question for me is, would changing NPC pixel X/Y in that script with a Read Pass Block to determine where walls are work for wallmap collision without having to script wallmaps for each map?
Oh, and just a note about my script: I'm using the old-style "define script" method — it's what I'm used to, and it works better with HSSEd.exe, 'cause I can hit F2 and have it list things like the scripts in my file, Global variables, etc. — I think it might need to be updated a little, thouigh, so that it supports the 'plotscript' command. >.> |
|
Back to top |
|
 |
Bob the Hamster OHRRPGCE Developer

Joined: 22 Feb 2003 Posts: 2526 Location: Hamster Republic (Southern California Enclave)
|
Posted: Fri Oct 17, 2008 10:49 am Post subject: |
|
|
Kizul Emeraldfire wrote: | Oh, and just a note about my script: I'm using the old-style "define script" method — it's what I'm used to, and it works better with HSSEd.exe, 'cause I can hit F2 and have it list things like the scripts in my file, Global variables, etc. — I think it might need to be updated a little, thouigh, so that it supports the 'plotscript' command. >.> |
Dang it. I am going to have to figure out a way to make people stop using HssEd.
I can't update it because it is written in Delphi 4, and depends on a bunch of random Delphi add-ons that I didn't document and didn't save copies of.
What I should do is write a HamsterSpeak plugin for some cool code editor that would be able to do the same things that HssEd can do (better, and faster, and less crashy) |
|
Back to top |
|
 |
Kizul Emeraldfire Type: Cyber Dragoon

Joined: 26 Mar 2004 Posts: 229
|
Posted: Fri Oct 17, 2008 10:58 am Post subject: |
|
|
James Paige wrote: | Kizul Emeraldfire wrote: | Oh, and just a note about my script: I'm using the old-style "define script" method — it's what I'm used to, and it works better with HSSEd.exe, 'cause I can hit F2 and have it list things like the scripts in my file, Global variables, etc. — I think it might need to be updated a little, thouigh, so that it supports the 'plotscript' command. >.> |
Dang it. I am going to have to figure out a way to make people stop using HssEd.
I can't update it because it is written in Delphi 4, and depends on a bunch of random Delphi add-ons that I didn't document and didn't save copies of.
What I should do is write a HamsterSpeak plugin for some cool code editor that would be able to do the same things that HssEd can do (better, and faster, and less crashy) |
Heh! xD I'm mostly just using it because when I hit some of the F-keys, it shows the cool floaty modules with things like the script dictionary, a list of the scripts/Globals/constants in the file, et cetera. The only real bug I've ever encountered with it is, it keeps giving me access violations after selecting a whole lot of text. I can deal with that, though.
If you were to make a new HssEd (OR a plugin for something else), I'd be all for it — just as long as it kept F-key function stuff from the old HssEd, and had syntax highlighting — preferably customizable as well, because I like the red text-on-black background setting I'm using for HssEd.  |
|
Back to top |
|
 |
Camdog
Joined: 08 Aug 2003 Posts: 606
|
Posted: Fri Oct 17, 2008 11:54 am Post subject: |
|
|
I threw together a plug-in for Crimson Editor (a neat freeware text editor) that highlights HamsterSpeak code, and indents based on ( and ). It also does neat stuff like highlight the corresponding opening or closing paren depending on where your cursor is, and it's easy to put together custom tools so you can do things like compile with a keypress.
It isn't perfect, as Crimson Editor refuses to believe keywords are not delimited by spaces, but I like it. If anyone is interested, I could send it their way. |
|
Back to top |
|
 |
Bob the Hamster OHRRPGCE Developer

Joined: 22 Feb 2003 Posts: 2526 Location: Hamster Republic (Southern California Enclave)
|
Posted: Fri Oct 17, 2008 2:33 pm Post subject: |
|
|
The spaces-in-keywords thing is a big problem fro most source code editors. Very few languages allow spaces in keywords, so many editors don't support it. |
|
Back to top |
|
 |
Kizul Emeraldfire Type: Cyber Dragoon

Joined: 26 Mar 2004 Posts: 229
|
Posted: Sat Oct 18, 2008 12:24 pm Post subject: |
|
|
Well, here it is, as complete as it'll get for now.
Even though I worked out the compiler-unfriendly bugs, it still seems to have a few — namely, only one NPC spawns, and in the lower-right corner. I can't figure out how to fix it. :/
The good news is, thanks to the 'exit script' command, my scripts no longer stack up like they did when I made that Final Fantasy Mystic Quest Map Emulator thing! (well they DO, but you practically have to press the two keys one after another in the same tick to do it)
Oh, by the way, a few notes: the 'W' key kicks up the menu, 'A' exits it, and the Right Shift key Game-Overs.
Anyway, thought I'd let you guys have a crack at this script to crush the NPC-spawn bug that I can't get rid of — it LOOKS like it should work the way I want it to, and I can't figure out why it doesn't. >.<
Edit: maybe this should be split off into the Plotscripting Help forum — it's sorta gone off-topic from where I'd originally started it.  |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|