Jump to content

Photo

Custom Zscripts I had generated using AI


  • This topic is locked This topic is locked
5 replies to this topic

#1 masterlink3000

masterlink3000

    Illustrious

  • Members
  • Real Name:Nick
  • Location:Mount Pleasant

Posted 14 February 2024 - 07:47 PM

Here is two zscripts I like someone with experience to try out. One is turning enemies into ice with a ice wand and the other is for selecting multiple screens for Link to move around on like in A Link to the Past.

If these work, it would actually be pretty neat.

-----------
 


```zscript
#include "std.zh" // Include standard ZScript library

const int ICE_DURATION = 60; // Duration in frames for the enemy to be frozen

int iceTimer = 0; // Timer to keep track of the remaining time for the enemy to be frozen

script void onGameStart()
{
// This script is executed when the game starts
// Add your custom code here
}

script void onEnemyDefeated()
{
// This script is executed when an enemy is defeated
// Add your custom code here
}

script void onWeaponUse()
{
// This script is executed when the player uses the custom weapon
// Add your custom code here

// Check if the player is facing an enemy
if (game.player.direction == direction_up && game.enemy.up)
{
// Freeze the enemy by setting the ice timer
iceTimer = ICE_DURATION;

// Add your custom code here to handle the frozen enemy

// Optional: Play a sound effect or animation to indicate the freezing effect
}
else if (game.player.direction == direction_down && game.enemy.down)
{
iceTimer = ICE_DURATION;
}
else if (game.player.direction == direction_left && game.enemy.left)
{
iceTimer = ICE_DURATION;
}
else if (game.player.direction == direction_right && game.enemy.right)
{
iceTimer = ICE_DURATION;
}
}

// Add more custom scripts as per your requirements

// Entry point for the script
void main()
{
// Main game loop
while (true)
{
// Check for game events and execute corresponding scripts
if (game.start)
{
onGameStart();
}

if (game.enemy.defeated)
{
onEnemyDefeated();
}

// Check if the ice timer is active
if (iceTimer > 0)
{
// Decrease the ice timer
iceTimer--;

// Add your custom code here to handle the frozen enemy

// Check if the ice timer has expired
if (iceTimer == 0)
{
// Add your custom code here to handle the unfrozen enemy

// Optional: Play a sound effect or animation to indicate the thawing effect
}
}

// Add more event checks and script executions as per your requirements

// Delay between each iteration of the game loop
waitFrame();
}
}
```

Please note that this is a basic template to help you get started. You'll need to further customize and expand this code based on your specific weapon and enemy behavior requirements. Additionally, this code assumes that you have already set up the enemy sprites and player sprites in ZQuest.

Remember to refer to the official documentation, tutorials, and community resources for more advanced concepts and techniques in ZScript. Good luck with your custom weapon in Zelda Classic!

----------

```zscript
#include "std.zh" // Include standard ZScript library

const int SCREEN_WIDTH = 256; // Width of a single screen
const int SCREEN_HEIGHT = 176; // Height of a single screen

const int MOVE_SPEED = 2; // Speed at which Link moves

int currentScreenX = 0; // Current X-coordinate of the screen
int currentScreenY = 0; // Current Y-coordinate of the screen

int playerX = 0; // Current X-coordinate of Link
int playerY = 0; // Current Y-coordinate of Link

int playerDirection = direction_down; // Current direction Link is facing

void moveLink(int dx, int dy)
{
// Calculate the new position for Link
int newX = playerX + dx;
int newY = playerY + dy;

// Check if the new position is within the screen bounds
if (newX >= 0 && newX < SCREEN_WIDTH && newY >= 0 && newY < SCREEN_HEIGHT)
{
// Update Link's position
playerX = newX;
playerY = newY;

// Update the screen position if needed
if (playerX < 0)
{
playerX = SCREEN_WIDTH - 1;
currentScreenX--;
}
else if (playerX >= SCREEN_WIDTH)
{
playerX = 0;
currentScreenX++;
}

if (playerY < 0)
{
playerY = SCREEN_HEIGHT - 1;
currentScreenY--;
}
else if (playerY >= SCREEN_HEIGHT)
{
playerY = 0;
currentScreenY++;
}
}
}

script void onGameStart()
{
// This script is executed when the game starts
// Add your custom code here
}

script void onKeyPress(int key)
{
// This script is executed when a key is pressed
// Add your custom code here

// Move Link based on the pressed key
if (key == key_up)
{
moveLink(0, -MOVE_SPEED);
playerDirection = direction_up;
}
else if (key == key_down)
{
moveLink(0, MOVE_SPEED);
playerDirection = direction_down;
}
else if (key == key_left)
{
moveLink(-MOVE_SPEED, 0);
playerDirection = direction_left;
}
else if (key == key_right)
{
moveLink(MOVE_SPEED, 0);
playerDirection = direction_right;
}
}

// Add more custom scripts as per your requirements

// Entry point for the script
void main()
{
// Main game loop
while (true)
{
// Check for game events and execute corresponding scripts
if (game.start)
{
onGameStart();
}

// Update the game screen based on the current position
game.screen.x = currentScreenX;
game.screen.y = currentScreenY;

// Update Link's position and direction
game.player.x = playerX;
game.player.y = playerY;
game.player.direction = playerDirection;

// Add more event checks and script executions as per your requirements

// Delay between each iteration of the game loop
waitFrame();
}
}
```

Please note that this is a basic template to help you get started. You'll need to further customize and expand this code based on your specific quest requirements. Additionally, this code assumes that you have already set up the screens and player sprites in ZQuest.

Remember to refer to the official documentation, tutorials, and community resources for more advanced concepts and techniques in ZScript. Good luck with your custom quest in Zelda Classic!



#2 Taco Chopper

Taco Chopper

    protector of the darn forum

  • Administrators
  • Pronouns:He / Him
  • Location:South Australia

Posted 14 February 2024 - 10:46 PM

I've gone ahead and put code boxes around the "scripts" to make these more readable. Please consider using them in future for content like this.
 
On the other hand, I can't stress enough that these won't compile - let alone work - in ZC just from a quick glance over them. For instance, functions like playerX, game.player.x, and key_left are incorrect. The AI says it's explicitly making a template for both of these scripts as well - but even then, the templates are so incorrect that they're not usable in their current state.
 
All in all, AI like ChatGPT isn't a "make zscripting easy" button. Please be wary of that when asking the AI to create scripts for use in quests.


  • Rambly, Mani Kanina, Jenny and 3 others like this

#3 Emily

Emily

    Scripter / Dev

  • ZC Developers

Posted 14 February 2024 - 11:53 PM

These scripts are entirely wrong on many levels, mostly including basic syntax- the coding language pictured here is simply not ZScript, but some form of AI-hallucinated gibberish (including some aspects of ZScript clearly, as it has things like "waitFrame()", albeit with the wrong capitalization so it still won't work - it clearly got some ZScript basics, and then mashed that together with its' C++ knowledge to try to give you an answer to your prompt, but the AI is just not good enough).

Sadly, AIs don't have a ton of ZScript in their training data sets, and really cannot replicate even the most basic zscript function in any way without heavy guidance from a human familiar with zscript already. We're a long way away from AI-assisted scripting.


  • Mani Kanina, Deedee, Matthew and 1 other like this

#4 Mani Kanina

Mani Kanina

    Rabbits!

  • Members

Posted 15 February 2024 - 12:48 AM

We are not going to sit and fucking debug AI generated crap. If you want to AI generate your code then sit down and learn scripting so you can debug it yourself.


  • Deedee likes this

#5 Deedee

Deedee

    Bug Frog Dragon Girl

  • Moderators
  • Real Name:Deedee
  • Pronouns:She / Her, They / Them
  • Location:Canada

Posted 15 February 2024 - 01:49 AM

If you tried to compile these yourself you would know these wouldn't work. Any effort I could put into this post would be more effort than you put into your own post, but.

Z3 scrolling ("move around multiple screens like in lttp") is only an easy script to make if the only thing you care about is the player moving around multiple screens. Anything that changes combos (bushes, switches, etc) would need to be handled custom, enemies would need to be custom, the tools the player uses would need to be custom. The difficulty of Z3 scrolling is that you need to handle everything; the engine feature of Z3 scrolling has been in development for months and while it's very far along, it's still not fully done and needs more testing to ensure that the underlying systems that were changed weren't broken. The difficulty of Z3 scrolling is the amount of patience you need to do it along with the baseline understanding of code; how the hell is an AI whose datasets are from before 2021 and don't include ZScript documentation in it's dataset supposed to even conceive of this? You'd need to feed the program the data it needs and even then the program can't playtest the code, so it's very likely to get it wrong. 

Like, lets look at the ice code.

Spoiler


This code in theory is meant to check if the player is facing the enemy to freeze the enemy; first of all, what is game.enemy.up? What is it doing? The obvious issue is that its not ZScript syntax, but even if it was, what is it doing? Is it checking if the enemy is facing up? If so, then all this code is doing is freezing enemies that are facing the same direction as the player, which makes no sense. Even if we're being generous and saying "oh, it checks if the enemy is directly above the player" (it isn't a function call because it has no () at the end, so it's extremely generous) and even if we ignore the fact that you're using 4 if statements to check for each direction indepently (if you're using a function to check if the enemy is right in front of the player, why isn't it just one if statement that takes the player's direction as an argument for the function?), this is still a bad script because ideally the ice rod would be a projectile, not just a "press button to freeze enemy in front of you". You wasted a bunch of code for an ugly unfun script when creating a projectile and checking if it hits an enemy is barely any effort at all.

Now, what happens when you hit an enemy with the ice rod? In your script, you declared a global variable iceTimer which gets set when a wepaon hits. Why is this a global variable? You'd want to be accessing a member of the enemy and setting that enemy's iceTimer; because it's global that means every enemy will be frozen if you freeze one. Even if you were doing this right, where is the handling for the enemy being frozen? There's code that decrements the timer but nothing that freezes the enemy in place. You'd ideally want the code handling in the enemy's code, which means the enemy has to have code attached and not just be a default enemy editor enemy, code that tells the enemy to not move and to do the frozen graphic (whether that be a custom tile, changing the color, or a simple overlay). This does none of it.

I surely don't need to point out that the script doesn't even follow the basic structure of a script; void Main() as "the main body of code" doesn't exist as a concept in scripts! "script void Gamestart" is trying to create a "void" type script, which doesn't even exist. There's just... there's nothing here! Half the script is "fill in the important bits yourself" and the other half isn't even correct! I shouldn't even need to point out that the only thing that the second script is doing is (incorrectly) trying to move Link around and nothing else, which would have been obvious had any effort at all been put in to look at it. 

I have spent 45 minutes writing this up, trying to explain why the nonsense spewed out by the nonsense machine you just used is nonsense. If there's a shortcut for Scripting, AI isn't it. Scripting is easy; you just need to think programmatically about things, and thinking programmatically is a transferable skill that can be applied to stuff like learning other programming languages, or even as simple as playing Baba is You. I'm increasingly annoyed and frustrated by people who don't want to put in the smallest amount of effort to try and learn scripting and expect to be spoonfed the answer to everything. ZScript was my first programming language; I learned it when I was 15 years old, and I'm the dumbest person I know. If I can learn it, then chances are you can learn it too. Please don't do this AI stuff again; all you've done is waste your own time, and the time of everyone in this thread. 45 minutes I'll never get back.


  • ShadowTiger and Matthew like this

#6 Jenny

Jenny

    Hero of Time

  • Members
  • Real Name:Jennette
  • Pronouns:She / Her

Posted 15 February 2024 - 06:44 AM

I think that's all that really needs to be said: AI is not a good tool for ZScript purposes.

 

That said, if you do have any interest in learning scripting yourself, consider checking these guides out as a (outdated but its the best we've got afaik) starting point:

 

https://www.purezc.n...showtopic=65586

https://www.purezc.n...showtopic=65588

https://www.purezc.n...showtopic=65589

 

Topic locked.
 


  • ShadowTiger, Rambly, Taco Chopper and 3 others like this


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users